51单片机74HC595驱动一位数码管显示程序
#include
#define uchar unsigned char #define uint unsigned int
sbit SCLK=P1^0; //SHCP 第11脚 移位寄存器时钟输入 sbit MOSI=P1^1; //DS 第14脚 串行数据输入
sbit RCLK=P1^2; //STCP 第12脚 存储寄存器时钟输入
unsigned char code Tab[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,
0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};//共阴数码管
void In_595(unsigned char dat) {
unsigned char i; for(i=0;i<8;i++) { if((dat<
_nop_(); _nop_(); SCLK=1; } }
void Out_595() {
RCLK=0; _nop_(); _nop_(); RCLK=1; _nop_(); _nop_(); RCLK=0; }
main()
{ In_595(Tab[8]); Out_595(); while(1) ; }
#include
#define uchar unsigned char #define uint unsigned int
sbit SCLK=P1^0; //SHCP 第11脚 移位寄存器时钟输入 sbit MOSI=P1^1; //DS 第14脚 串行数据输入
sbit RCLK=P1^2; //STCP 第12脚 存储寄存器时钟输入
unsigned char code Tab[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,
0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};//共阴数码管 void send(uchar dat) { uint i; for(i=0;i<8;i++) { if((dat<
_nop_(); _nop_(); SCLK=1; } RCLK=0; _nop_(); _nop_(); RCLK=1; }
main()
{ send(Tab[8]); while(1) ; }
相关推荐: