?? lab1.c
字號:
/****************************************************************
* Hi-Tech workshop exercise Lab1 *
*****************************************************************
* The program will display a binary count value on PORTD (LED) *
* every delay 200mS *
* *
* Files required: *
* *
* lab1.c *
* cnfig877a.h (Set the Configuration Word) *
* *
* pic.h (Hi-Tech file) *
* *
*****************************************************************
* *
* Notes: *
* *
* Device Fosc -> 16.00MHz (Clock supplied by target) *
* *
*****************************************************************/
#include <pic.h> // processor if/def file
#include "cnfig877a.h"
//**********************************
//* Function Prototype Declaration
//**********************************
void Init_System(void);
void Delay_x_mS(int);
void Delay_1mS(void);
// ================================================================
// **** Establish PIC16F877A Configuration Word
// **** == HS Oscillator Mode
// **** == Brown-Out Detect Enabled
// **** == Watch-Dog Timer Off
// **** == Code Protect Off
// **** == Low Voltage Programming Off
// **** == ICD2 Debug Mode On
__CONFIG ( HS_OSC & BODEN_ON & WDT_OFF & CP_OFF & LVP_OFF & DEBUG_ON );
// =================================================================
/*****************************
INITIALIZE SYSTEM
*****************************/
void Init_System(void)
{
PORTD = 0x00; // Initialize PORTD latch states
TRISD = 0x00; // set PORTD as outputs
};
//*********************************
//* Delay Routine with 16MHz
//*********************************
void Delay_x_mS( int N_mS )
{
int Loop_mS ;
for ( Loop_mS = 0 ; Loop_mS < N_mS ; Loop_mS++ )
{
Delay_1mS();
}
}
//*** Delay 1mS with 16MHz crystal
void Delay_1mS(void)
{
int Del_1mS;
for (Del_1mS = 0 ; Del_1mS < 199 ; Del_1mS ++ )
{
asm("nop");
asm("nop");
}
}
/*******************************************************************
MAIN PROGRAM BEGINS HERE
********************************************************************/
void main( void )
{
Init_System(); // Initialize System Function and Variables
while(1) // Infinite loop
{
Delay_x_mS(200); // Delay 200mS
PORTD++; // Increment PortD
};
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -