这是个点阵程序 重点就在那个date 为什么date为char型点阵才能显示0 为int型 点阵显示就不对
- #include<reg51.h>
- #include<intrins.h>
- #define uint unsigned int
- #define ucharunsigned char
- sbit RCLK=P3^5;
- sbit SRCLK=P3^6;
- sbit SER=P3^4;
- ucharledduan[]={0x00,0x00,0x7E,0x81,0x81,0x81,0x7E,0x00};
- ucharledwei[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
- void delay(uintz);
- void HC595(uchardate) //date必须是char 型
- {
- uint a;
- SRCLK=0;
- RCLK=0;
- for(a=0;a<8;a++)
- {
- SER=date>>7;
- date<<=1;
- SRCLK=1;
- SRCLK=0;
- }
- RCLK=1;
-
- RCLK=0;
- }
- void main()
- {
- P0=0x7f;
- while(1)
- { uchar i=0;
-
- for(i=0;i<8;i++)
- {
- P0=ledwei[ i];
- HC595(ledduan[ i]);
- delay(1);
- HC595(0x00);
- }
- }
-
- }
-
- void delay(uint z)
- {
- uint x,y;
- for(x=z;x>0;x--)
- for(y=100;y>0;y--);
- }
复制代码
|