📄 rgb_led.lst
字号:
1: //include file
2: #include <pic.h>
3:
4: //16F84 configuration
5: __CONFIG(0x3FF1);
6:
7: //portb macro
8: #define PORTBIT(adr, bit) ((unsigned)(&adr)*8+(bit))
9:
10: //portb pin assignment
11: static bit LED0 @ PORTBIT(PORTB, 0);
12: static bit LED1 @ PORTBIT(PORTB, 1);
13: static bit LED2 @ PORTBIT(PORTB, 2);
14: static bit LED3 @ PORTBIT(PORTB, 3);
15: static bit LED4 @ PORTBIT(PORTB, 4);
16: static bit LED5 @ PORTBIT(PORTB, 5);
17: static bit LED6 @ PORTBIT(PORTB, 6);
18: static bit LED7 @ PORTBIT(PORTB, 7);
19:
20: //global variables
21: unsigned int i; //for loop pause
22: unsigned int c; //for loop event loop
23:
24: //functions
25: void pause_action(); //pause
26: void blink_redgreen(); //blink red then green
27: void blink_baf(); //blink red and green back and forth
28: void alt_blink(); //every other red then green
29: void blink_sequence(); //blinks red one at a time
30: //end functions
31:
32: //main function
33: void main(void)
34: {
35: TRISB = 0x00;
36: PORTB = 0b00000000;
37:
38: while(1)
39: {
40:
41: blink_redgreen();
42: blink_baf();
43: alt_blink();
44: blink_sequence();
45:
46: };
47:
48: }
49: //end main function
50:
51: void pause_action()
52: {
53:
54: for(i=0; i<4000; i++);
55: for(i=0; i<4000; i++);
56: for(i=0; i<4000; i++);
57: for(i=0; i<4000; i++);
58: for(i=0; i<4000; i++);
59: for(i=0; i<4000; i++);
60:
61: };
62:
63: void blink_redgreen()
64: {
65:
66: for(c=0; c<10; c++)
67: {
68:
69: PORTB = 0b10101010;
70: pause_action();
71:
72: PORTB = 0b01010101;
73: pause_action();
74:
75: };
76:
77: };
78:
79: void blink_baf()
80: {
81:
82: for(c=0; c<10; c++)
83: {
84:
85: PORTB = 0b10100101;
86: pause_action();
87:
88: PORTB = 0b01011010;
89: pause_action();
90:
91: };
92:
93: };
94:
95: void alt_blink()
96: {
97:
98: for(c=0; c<10; c++)
99: {
100:
101: PORTB = 0b10011001;
102: pause_action();
103:
104: PORTB = 0b01100110;
105: pause_action();
106:
107: };
108:
109: };
110:
111: void blink_sequence()
112: {
113:
114: for(c=0; c<10; c++)
115: {
116:
117: PORTB = 0b10010101;
118: pause_action();
119:
120: PORTB = 0b01100101;
121: pause_action();
122:
123: PORTB = 0b01011001;
124: pause_action();
125:
126: PORTB = 0b01010110;
127: pause_action();
128:
129: };
130:
131: };
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -