📄 read_adc.lst
字号:
1: #include <pic.h>
2:
3:
4: void main()
5: {
6: unsigned int I,j,k,L,i,msg;
7: unsigned char A,B,z;
8: #define ADCOSC 0b10000000
9: #define CHANNEL0 0b00000000 // ADC channel 0 (RA0/AN0)
10: #define ADCON 0b00000101 // ADC power on
11: ADRESL=0x00;
12: ADRESH=0x00;
13: TRISB=0x00;
14: PORTB=0x00;
15: TRISD=0x00;
16: PORTD=0x00;
17: TRISC=0x00;
18: PORTC=0x00;
19: ADCON0 = ADCOSC | CHANNEL0 | ADCON;
20: ADCON1=0b10000000;
21: ADCON0= ADCON0 | 0b00000100; //start conversion
22: while(1)
23: {
24: PORTD=ADRESH & 0b00000010;
25: PORTB=ADRESL & 0b11111111;
26: z=0b00010000;
27: PORTC=z;
28: while(ADGO);
29: {
30: A=ADRESH & 0x02; //0b00000010
31: B=ADRESH & 0x01; //0b00000001
32: L = ADRESL;
33: L += (ADRESH << 8);
34:
35: if(A==2)
36: {j=512;}
37: else
38: {j=0;}
39: if(B==0)
40: {k=256;}
41: else
42: {k=0;}
43: I=j+k+L;
44: for(i=0;i<=3;i++)
45: {
46: msg=I%10;
47: msg=msg | 0b10000000; //DATA TO PORTD & DOT
48: PORTD=msg;
49: z=z>>1;
50: PORTC=z; //LED ON COMMAND PORT
51: PORTC=z;
52: PORTC=z;
53: I=I/10;
54: PORTC=0;
55: }
56: }
57: }}
58:
59:
60:
61:
62:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -