这个是电路图 下边是我的程序 大佬帮帮忙 万分感谢- #include <at8.h>
- #include "at8_constant.h"
- unsigned int v,ge,shi,bai;
- unsigned int R_AIN1_DATA_HB;
- unsigned int R_AIN1_DATA_LB;
- unsigned int ADC_DATA;
- #define UPDATE_REG(x) __asm__("MOVR _" #x ",F")
- #define A PORTAbits.PA0
- #define B PORTAbits.PA4
- #define C PORTAbits.PA7
- #define D PORTBbits.PB3
- #define E PORTBbits.PB1
- #define F PORTAbits.PA1
- #define G PORTAbits.PA6
- #define DP PORTAbits.PA5
- #define W1 PORTBbits.PB0
- #define W2 PORTAbits.PA2
- #define W3 PORTAbits.PA3
- void display(unsigned int i);
- void weixuan();
- //! interrupt service routine
- void isr(void) __interrupt(0)
- {
- ADRbits.ADIF = 0;
- R_AIN1_DATA_HB = ADD;
- R_AIN1_DATA_LB = 0x0F & ADR;
- ADMDbits.START = 1;
- }
- void main(void)
- {
- // R_AIN1_DATA_HB=R_AIN1_DATA_LB=0x00;
- //----- Initial GPIO-----
- IOSTA = 0x00;
- IOSTB = 0X04;
- PORTA = 0xFF;
- PORTB = 0xFF;
- INTE = 0x00;
- //----- Initial ADC-----
- ADMD = C_ADC_En | C_ADC_CH_Dis | C_ADC_PB2 ;
- ADVREFH = C_Vrefh_2V;
- ADR = C_Ckl_Div1;
- ADCR = C_Sample_8clk | C_12BIT;
- PACON = C_PB2_AIN7;
- ADMDbits.GCHS = 1;
- ADRbits.ADIF = 0;
- ADRbits.ADIE = 1;
- ADMDbits.START = 1;
- ENI();
- while(1)
- {
- while(ADMDbits.EOC==0);
- ADC_DATA = ((unsigned int)R_AIN1_DATA_HB << 4 )+ R_AIN1_DATA_LB;
- v=(unsigned int)ADC_DATA/10;
- ge = v%10;
- shi = v/10%10;
- bai = v/100%10;
- weixuan();
- }
- }
- void display(unsigned int i)
- {
- switch(i)
- {
- case 0:A=0;B=0;C=0;D=0;E=0;F=0;G=1;DP=1;break;
- case 1:A=1;B=0;C=0;D=1;E=1;F=1;G=1;DP=1;break;
- case 2:A=0;B=0;C=1;D=0;E=0;F=1;G=0;DP=1;break;
- case 3:A=0;B=0;C=0;D=0;E=1;F=1;G=0;DP=1;break;
- case 4:A=1;B=0;C=0;D=1;E=1;F=0;G=0;DP=1;break;
- case 5:A=0;B=1;C=0;D=0;E=1;F=0;G=0;DP=1;break;
- case 6:A=0;B=1;C=0;D=0;E=0;F=0;G=0;DP=1;break;
- case 7:A=0;B=0;C=0;D=1;E=1;F=1;G=1;DP=1;break;
- case 8:A=0;B=0;C=0;D=0;E=0;F=0;G=0;DP=1;break;
- case 9:A=0;B=0;C=0;D=0;E=1;F=0;G=0;DP=1;break;
- }
- }
- void weixuan()
- {
- unsigned int i,j;
- while(1)
- {
- for(i=0;i<3;i++)
- {
- switch(i)
- {
- case(0):W1=0;W2=0;W3=1;display(ge);break;
- case(1):/*if(v>10)*/W2=1;W1=0;W3=0;display(shi);break;
- case(2):/*if(v>100)*/W1=1;W2=0;W3=0;display(bai);break;
- }
- j=50;
- while(j--);
复制代码
|