📄 lab6.lst
字号:
1:
2:
3: /****************************************************************
4: * Hi-Tech workshop exercise Lab6 *
5: *****************************************************************
6: * *
7: * Files required: *
8: * *
9: * lab6.c *
10: * cnfig877a.h (Set the Configuration Word) *
11: * *
12: * pic.h (Hi-Tech file) *
13: * *
14: *****************************************************************
15: * *
16: * Notes: *
17: * *
18: * Device Fosc -> 16.00MHz (Clock supplied by target) *
19: * *
20: *****************************************************************/
21:
22: #include <pic.h> // processor if/def file
23: #include "cnfig877a.h"
24:
25: //**********************************
26: //* Function Prototype Declaration
27: //**********************************
28: void interrupt isr_Sevr ( void );
29:
30: // ================================================================
31: // **** Establish PIC16F877A Configuration Word
32: // **** == HS Oscillator Mode
33: // **** == Brown-Out Detect Enabled
34: // **** == Watch-Dog Timer Off
35: // **** == Code Protect Off
36: // **** == Low Voltage Programming Off
37: // **** == ICD2 Debug Mode On
38:
39: __CONFIG ( HS_OSC & BODEN_ON & WDT_OFF & CP_OFF & LVP_OFF & DEBUG_ON );
40:
41: // =================================================================
42:
43: volatile unsigned char Long_Count ;
44: volatile unsigned char Direct_LED ;
45: volatile unsigned char Dir_Count ;
46:
47: void main(void)
48: {
49: TRISD=0x00; // Set output port for LED driver
50: PORTD=0b00000001; // Set b0 of LED is On
51:
52: T2CON=0b01111110; // Timer2 On, Postscale=16, Prescale=16
53: TMR2IE=1; // Enable Timer2 Interrupt
54: PEIE=1; // Set Timer2 for High Priority
55: GIE=1; // Enable High Priority Interrupt
56: PR2 = 155; //(16Mhz/4) [16*16*(155+1)] = 10mS
57:
58: Long_Count=0;
59: Direct_LED=0;
60: Dir_Count=0;
61:
62: while(1); // Loop Here!
63: }
64:
65:
66: //***********************************************
67: //* Interrupt Service Routine *
68: //***********************************************
69:
70: void interrupt isr_Sevr ( void )
71:
72: {
73: TMR2IF=0; // Clear Timer2 interrupt Flag
74:
75: if (Long_Count <=10) Long_Count++; // 10mS * 10 = 100mS
76: else
77: {
78: Long_Count=0; // Time is 100mS, do the function
79:
80: if (Direct_LED==0x00) // Right or Left shift
81: {
82: PORTD<<=1; // LED left shift
83: Dir_Count++;
84: if (Dir_Count==7) // End of LED position?
85: {
86: Dir_Count=0; // Yes, set flag of right shift
87: Direct_LED=0x1;
88: }
89: }
90: else
91: {
92: PORTD>>=1; // LED right shift
93: Dir_Count++;
94: if (Dir_Count==7)
95: {
96: Dir_Count=0;
97: Direct_LED=0x00;
98: }
99: }
100: }
101: }
102:
103:
104:
105:
106:
107:
108:
109:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -