//带锁存功能的串入并出芯片。这里给出74hc595的c51驱动程序。 //定时器晶体振荡器11.0592M. #i nclude<reg51.h> #i nclude <INTRINS.H> #define uint unsigned int #define uchar unsigned char #define nop() _nop_();_nop_(); sbit CLK=P2^0; sbit DAT=P2^1; sbit RCLK=P2^2; //sbit CS=P2^3;
uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xff};//0-9,-,全灭
void sendbyte(uchar byte) { uchar num,c; num=tab[byte]; for(c=0;c<8;c++) { CLK=0; DAT=num&0x80; num=num<<1; CLK=1; } // RCLK=0; // nop(); // nop(); // RCLK=1; } void out595(void) { RCLK=0; nop(); RCLK=1; } void display(uchar word) { uchar i,j; i=word/10; j=word-10*i; sendbyte(j); sendbyte(i); out595(); }
main() { while(1) { display(19); display(86); } while(1); }
|