- #include<reg52.h>
- #define u16 unsigned int
- #define u8 unsigned char
- sbit shizhong = P2^0;
- sbit shuju = P2^1;
- sbit suocun = P2^2;
- u16 code wei[]={0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,0x0100,0x0200,0x0400,0x0800,0x1000,0x2000,0x4000,0x8000};
- u8 code duan[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};
- void HC595_qudong(u8 duan595,u16 wei595) //595驱动函数
- {
- u8 i=0;
- for(i=0;i<8;i++) //段选
- {
- shizhong=0;
- shuju=duan595&0x80;
- duan595<<=1;
- shizhong=1;
- }
- for(i=0;i<16;i++) //位选
- {
- shizhong=0;
- shuju=wei595&0x8000;
- wei595<<=1;
- shizhong=1;
- }
-
- suocun=1; //输出
- shuju=0;
- suocun=0;
- }
- void main()
- {
- u8 i;
- u8 display_num[16]={1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6};
-
- while(1)
- {
- for(i=0;i<16;i++)
- {
- HC595_qudong(duan[display_num[i]],wei[i]);
- }
- }
- }
复制代码
|