86
6110
1万
超级版主
使用道具 举报 送花
#include <AI8H.H> unsigned char Count; /*----------------------------延时10us@AI8@11.0592MHz----------------------------*/ void Delay_10us(void) { unsigned char data i; i=35; while(--i); } /*----------------------------延时x10us----------------------------*/ void Delay_x10us(unsigned char x) { while(x--) Delay_10us(); } void PIN1_ENA(bit x){P2M0|=0x01;P2M1&=0xFE;P20=x;} void PIN1_DIS(void){P2M0&=0xFE;P2M1|=0x01;} void PIN2_ENA(bit x){P2M0|=0x02;P2M1&=0xFD;P21=x;} void PIN2_DIS(void){P2M0&=0xFD;P2M1|=0x02;} void PIN3_ENA(bit x){P2M0|=0x04;P2M1&=0xFB;P22=x;} void PIN3_DIS(void){P2M0&=0xFB;P2M1|=0x04;} void PIN4_ENA(bit x){P2M0|=0x08;P2M1&=0xf7;P23=x;} void PIN4_DIS(void){P2M0&=0xf7;P2M1|=0x08;} void PIN5_ENA(bit x){P2M0|=0x10;P2M1&=0xEF;P24=x;} void PIN5_DIS(void){P2M0&=0xEF;P2M1|=0x10;} void Clear_Display(void) { PIN1_DIS(); PIN2_DIS(); PIN3_DIS(); PIN4_DIS(); PIN5_DIS(); } void Display(unsigned char x,unsigned char brightness) { unsigned char a,b,c; if(x>=200) { a=0xFF; b=0xFF; c=0xFF; } else { a=x/100; b=x%100/10; c=x%10; } if(a==1) {PIN3_ENA(1);PIN4_ENA(0);Delay_x10us(brightness);PIN3_DIS();PIN4_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(a==1) {PIN2_ENA(1);PIN4_ENA(0);Delay_x10us(brightness);PIN2_DIS();PIN4_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(b==0||b==2||b==3||b==5||b==6||b==7||b==8||b==9) {PIN2_ENA(1);PIN3_ENA(0);Delay_x10us(brightness);PIN2_DIS();PIN3_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(b==0||b==1||b==2||b==3||b==4||b==7||b==8||b==9) {PIN3_ENA(1);PIN2_ENA(0);Delay_x10us(brightness);PIN3_DIS();PIN2_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(b==0||b==1||b==3||b==4||b==5||b==6||b==7||b==8||b==9) {PIN4_ENA(1);PIN3_ENA(0);Delay_x10us(brightness);PIN4_DIS();PIN3_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(b==0||b==2||b==3||b==5||b==6||b==8||b==9) {PIN4_ENA(1);PIN2_ENA(0);Delay_x10us(brightness);PIN4_DIS();PIN2_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(b==0||b==2||b==6||b==8) {PIN5_ENA(1);PIN2_ENA(0);Delay_x10us(brightness);PIN5_DIS();PIN2_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(b==0||b==4||b==5||b==6||b==8||b==9) {PIN5_ENA(1);PIN3_ENA(0);Delay_x10us(brightness);PIN5_DIS();PIN3_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(b==2||b==3||b==4||b==5||b==6||b==8||b==9) {PIN5_ENA(1);PIN4_ENA(0);Delay_x10us(brightness);PIN5_DIS();PIN4_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(c==0||c==2||c==3||c==5||c==6||c==7||c==8||c==9) {PIN1_ENA(1);PIN2_ENA(0);Delay_x10us(brightness);PIN1_DIS();PIN2_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(c==0||c==1||c==2||c==3||c==4||c==7||c==8||c==9) {PIN2_ENA(1);PIN1_ENA(0);Delay_x10us(brightness);PIN2_DIS();PIN1_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(c==0||c==1||c==3||c==4||c==5||c==6||c==7||c==8||c==9) {PIN1_ENA(1);PIN3_ENA(0);Delay_x10us(brightness);PIN1_DIS();PIN3_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(c==0||c==2||c==3||c==5||c==6||c==8||c==9) {PIN3_ENA(1);PIN1_ENA(0);Delay_x10us(brightness);PIN3_DIS();PIN1_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(c==0||c==2||c==6||c==8) {PIN1_ENA(1);PIN4_ENA(0);Delay_x10us(brightness);PIN1_DIS();PIN4_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(c==0||c==4||c==5||c==6||c==8||c==9) {PIN4_ENA(1);PIN1_ENA(0);Delay_x10us(brightness);PIN4_DIS();PIN1_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(c==2||c==3||c==4||c==5||c==6||c==8||c==9) {PIN5_ENA(1);PIN1_ENA(0);Delay_x10us(brightness);PIN5_DIS();PIN1_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); } void Init(void) { Clear_Display(); TL0=0x00; TH0=0x4C; TF0=0; ET0=1; EA=1; TR0=1; } void main(void) { Init(); while(1) { Display(Count,5); } } void Timer0(void) interrupt 1 { static unsigned char count; count++; if(count==2) { count=0; Count++; if(Count==200) Count=0; } }复制代码
#include <AI8H.H> unsigned int Count; /*----------------------------延时10us@AI8@11.0592MHz----------------------------*/ void Delay_10us(void) { unsigned char data i; i=35; while(--i); } /*----------------------------延时x10us----------------------------*/ void Delay_x10us(unsigned char x) { while(x--) Delay_10us(); } void PIN1_ENA(bit x){P2M0|=0x01;P2M1&=0xFE;P20=x;} void PIN1_DIS(void){P2M0&=0xFE;P2M1|=0x01;} void PIN2_ENA(bit x){P2M0|=0x02;P2M1&=0xFD;P21=x;} void PIN2_DIS(void){P2M0&=0xFD;P2M1|=0x02;} void PIN3_ENA(bit x){P2M0|=0x04;P2M1&=0xFB;P22=x;} void PIN3_DIS(void){P2M0&=0xFB;P2M1|=0x04;} void PIN4_ENA(bit x){P2M0|=0x08;P2M1&=0xf7;P23=x;} void PIN4_DIS(void){P2M0&=0xf7;P2M1|=0x08;} void PIN5_ENA(bit x){P2M0|=0x10;P2M1&=0xEF;P24=x;} void PIN5_DIS(void){P2M0&=0xEF;P2M1|=0x10;} void PIN6_ENA(bit x){P2M0|=0x20;P2M1&=0xDF;P25=x;} void PIN6_DIS(void){P2M0&=0xDF;P2M1|=0x20;} void Clear_Display(void) { PIN1_DIS(); PIN2_DIS(); PIN3_DIS(); PIN4_DIS(); PIN5_DIS(); PIN6_DIS(); } void Display(unsigned int x,bit dp,unsigned char brightness) { unsigned char a,b,c,d; if(x>=2000) { a=0xFF; b=0xFF; c=0xFF; d=0xFF; } else { a=x/1000; b=x%1000/100; c=x%100/10; d=x%10; } if(a==1) {PIN4_ENA(1);PIN3_ENA(0);Delay_x10us(brightness);PIN4_DIS();PIN3_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(a==1) {PIN5_ENA(1);PIN3_ENA(0);Delay_x10us(brightness);PIN5_DIS();PIN3_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(b==0||b==2||b==3||b==5||b==6||b==7||b==8||b==9) {PIN2_ENA(1);PIN1_ENA(0);Delay_x10us(brightness);PIN2_DIS();PIN1_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(b==0||b==1||b==2||b==3||b==4||b==7||b==8||b==9) {PIN3_ENA(1);PIN1_ENA(0);Delay_x10us(brightness);PIN3_DIS();PIN1_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(b==0||b==1||b==3||b==4||b==5||b==6||b==7||b==8||b==9) {PIN4_ENA(1);PIN1_ENA(0);Delay_x10us(brightness);PIN4_DIS();PIN1_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(b==0||b==2||b==3||b==5||b==6||b==8||b==9) {PIN5_ENA(1);PIN1_ENA(0);Delay_x10us(brightness);PIN5_DIS();PIN1_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(b==0||b==2||b==6||b==8) {PIN6_ENA(1);PIN1_ENA(0);Delay_x10us(brightness);PIN6_DIS();PIN1_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(b==0||b==4||b==5||b==6||b==8||b==9) {PIN3_ENA(1);PIN2_ENA(0);Delay_x10us(brightness);PIN3_DIS();PIN2_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(b==2||b==3||b==4||b==5||b==6||b==8||b==9) {PIN4_ENA(1);PIN2_ENA(0);Delay_x10us(brightness);PIN4_DIS();PIN2_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(c==0||c==2||c==3||c==5||c==6||c==7||c==8||c==9) {PIN1_ENA(1);PIN2_ENA(0);Delay_x10us(brightness);PIN1_DIS();PIN2_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(c==0||c==1||c==2||c==3||c==4||c==7||c==8||c==9) {PIN1_ENA(1);PIN3_ENA(0);Delay_x10us(brightness);PIN1_DIS();PIN3_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(c==0||c==1||c==3||c==4||c==5||c==6||c==7||c==8||c==9) {PIN1_ENA(1);PIN4_ENA(0);Delay_x10us(brightness);PIN1_DIS();PIN4_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(c==0||c==2||c==3||c==5||c==6||c==8||c==9) {PIN1_ENA(1);PIN5_ENA(0);Delay_x10us(brightness);PIN1_DIS();PIN5_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(c==0||c==2||c==6||c==8) {PIN1_ENA(1);PIN6_ENA(0);Delay_x10us(brightness);PIN1_DIS();PIN6_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(c==0||c==4||c==5||c==6||c==8||c==9) {PIN5_ENA(1);PIN2_ENA(0);Delay_x10us(brightness);PIN5_DIS();PIN2_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(c==2||c==3||c==4||c==5||c==6||c==8||c==9) {PIN6_ENA(1);PIN2_ENA(0);Delay_x10us(brightness);PIN6_DIS();PIN2_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(dp==1) {PIN6_ENA(1);PIN3_ENA(0);Delay_x10us(brightness);PIN6_DIS();PIN3_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(d==0||d==2||d==3||d==5||d==6||d==7||d==8||d==9) {PIN2_ENA(1);PIN3_ENA(0);Delay_x10us(brightness);PIN2_DIS();PIN3_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(d==0||d==1||d==2||d==3||d==4||d==7||d==8||d==9) {PIN2_ENA(1);PIN4_ENA(0);Delay_x10us(brightness);PIN2_DIS();PIN4_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(d==0||d==1||d==3||d==4||d==5||d==6||d==7||d==8||d==9) {PIN2_ENA(1);PIN5_ENA(0);Delay_x10us(brightness);PIN2_DIS();PIN5_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(d==0||d==2||d==3||d==5||d==6||d==8||d==9) {PIN2_ENA(1);PIN6_ENA(0);Delay_x10us(brightness);PIN2_DIS();PIN6_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(d==0||d==2||d==6||d==8) {PIN3_ENA(1);PIN4_ENA(0);Delay_x10us(brightness);PIN3_DIS();PIN4_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(d==0||d==4||d==5||d==6||d==8||d==9) {PIN3_ENA(1);PIN5_ENA(0);Delay_x10us(brightness);PIN3_DIS();PIN5_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); if(d==2||d==3||d==4||d==5||d==6||d==8||d==9) {PIN3_ENA(1);PIN6_ENA(0);Delay_x10us(brightness);PIN3_DIS();PIN6_DIS();}else Delay_x10us(brightness);Delay_x10us(10-brightness); } void Init(void) { Clear_Display(); TL0=0x00; TH0=0xEE; TF0=0; ET0=1; EA=1; TR0=1; } void main(void) { Init(); while(1) { Display(Count,1,5); } } void Timer0(void) interrupt 1 { static unsigned char count; count++; if(count==2) { count=0; Count++; if(Count==2000) Count=0; } }复制代码
本版积分规则 发表回复 回帖后跳转到最后一页
|手机版|深圳国芯人工智能有限公司 ( 粤ICP备2022108929号-2 )
GMT+8, 2025-9-15 21:58 , Processed in 0.137797 second(s), 63 queries .
Powered by Discuz! X3.5
© 2001-2025 Discuz! Team.