📄 lab1.lst
字号:
1:
2:
3: /****************************************************************
4: * Hi-Tech workshop exercise Lab1 *
5: *****************************************************************
6: * The program will display a binary count value on PORTD (LED) *
7: * every delay 200mS *
8: * *
9: * Files required: *
10: * *
11: * lab1.c *
12: * cnfig877a.h (Set the Configuration Word) *
13: * *
14: * pic.h (Hi-Tech file) *
15: * *
16: *****************************************************************
17: * *
18: * Notes: *
19: * *
20: * Device Fosc -> 16.00MHz (Clock supplied by target) *
21: * *
22: *****************************************************************/
23:
24: #include <pic.h> // processor if/def file
25: #include "cnfig877a.h"
26:
27: //**********************************
28: //* Function Prototype Declaration
29: //**********************************
30: void Init_System(void);
31: void Delay_x_mS(int);
32: void Delay_1mS(void);
33:
34: // ================================================================
35: // **** Establish PIC16F877A Configuration Word
36: // **** == HS Oscillator Mode
37: // **** == Brown-Out Detect Enabled
38: // **** == Watch-Dog Timer Off
39: // **** == Code Protect Off
40: // **** == Low Voltage Programming Off
41: // **** == ICD2 Debug Mode On
42:
43: __CONFIG ( HS_OSC & BODEN_ON & WDT_OFF & CP_OFF & LVP_OFF & DEBUG_ON );
44:
45: // =================================================================
46:
47: /*****************************
48: INITIALIZE SYSTEM
49: *****************************/
50:
51: void Init_System(void)
52: {
53: PORTD = 0x00; // Initialize PORTD latch states
54: TRISD = 0x00; // set PORTD as outputs
55: };
56:
57: //*********************************
58: //* Delay Routine with 16MHz
59: //*********************************
60:
61: void Delay_x_mS( int N_mS )
62: {
63: int Loop_mS ;
64:
65: for ( Loop_mS = 0 ; Loop_mS < N_mS ; Loop_mS++ )
66: {
67: Delay_1mS();
68: }
69:
70: }
71:
72: //*** Delay 1mS with 16MHz crystal
73:
74: void Delay_1mS(void)
75: {
76: int Del_1mS;
77:
78: for (Del_1mS = 0 ; Del_1mS < 199 ; Del_1mS ++ )
79: {
80: asm("nop");
81: asm("nop");
82: }
83: }
84:
85: /*******************************************************************
86: MAIN PROGRAM BEGINS HERE
87: ********************************************************************/
88:
89: void main( void )
90: {
91: Init_System(); // Initialize System Function and Variables
92:
93: while(1) // Infinite loop
94: {
95: Delay_x_mS(200); // Delay 200mS
96: PORTD++; // Increment PortD
97: };
98: }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -