用单个595,编写程序成功。可是两个级联不知如何写入数据使LED灯逐个点亮。请指教,一片595的代码如下:
#include <reg52.h> //51芯片管脚定义头文件 #include <intrins.h> //内部包含延时函数 _nop_(); #define uchar unsigned char #define uint unsigned int
uchar code DAT[8]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00};
sbit SDATA_595=P3^0; //串行数据输入 sbit SCLK_595 =P3^1; //移位时钟脉冲 sbit RCK_595 =P3^2; //输出锁存器控制脉冲
uchar temp;
/********************************************************/ /* */ /* 延时子程序 */ /* */ /********************************************************/
void delay(int ms) { int k; while(ms--) { for(k=0; k<250; k++) { _nop_(); _nop_(); _nop_(); _nop_(); } } }
/********************************************************/ /* */ /*将显示数据送入74HC595内部移位寄存器 */ /* */ /********************************************************/
void WR_595(void) { uchar j; for (j=0;j<8;j++) { temp=temp<<1; SDATA_595=CY; SCLK_595=1; //上升沿发生移位 _nop_(); _nop_(); SCLK_595=0; } }
/********************************************************/ /* */ /*将移位寄存器内的数据锁存到输出寄存器并显示 */ /* */ /********************************************************/
void OUT_595(void) { RCK_595=0; _nop_(); _nop_(); RCK_595=1; //上升沿将数据送到输出锁存器 _nop_(); _nop_(); _nop_(); RCK_595=0; }
main() { SCLK_595=0; RCK_595=1; while(1) { uchar i; for (i=0; i<8; i++) { temp=DAT; //取显示数据 WR_595(); OUT_595(); delay(30); } } }
|