3.hex为共阳极
另一个为共阴极
单片机源程序如下:
- #include<reg51.h>
- #define SEG P0
- unsigned char SMGD[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x83,0xf8,0x80,0x98}; //共阴极 段显0~9
- unsigned char SMGW[]={0x01,0x02,0x04,0x08}; //位选1~4
- unsigned int n;
- void delay(unsigned int i) //延时函数
- {
- while(i--);
- }
- void main(void) //主函数
- {
- unsigned char Temp;
- while(1)
- {
- switch (Temp%4)
- {
-
- case 0:P0 = SMGD[Temp%10];break;
- case 1:P0 = SMGD[Temp%10];break;
- case 2:P0 = SMGD[Temp%10];break;
- case 3:P0 = SMGD[Temp%10];break;
-
- }
- P0 =SMGW[Temp%4];
- Temp++;
- delay(50000);
- }
- }
复制代码
所有资料51hei提供下载:
数码管扫描(共阴极和共阳极).zip
(23.25 KB, 下载次数: 11)
|