Code:
#include <REGX52.H> sbit SDO = P2^0; sbit SCK = P2^1; sbit SCL = P2^2; sbit MR = P2^3; // reset thanh ghi sbit EN = P2^4; unsigned char m[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; int k,i; void delay(long time) { long n; for(n=0;n<time;n++) { ; } } void quet(unsigned char x) { int tam; for(i=0;i<8;i++) { tam=x; tam=tam&0x80; // lay tung bit if(tam==0x80) // SDO=1; // else // SDO=0; // x<<=1; // SCK=0; // tao xung, moi xung nhet vao 595 1 bit SCK=1; } } void main() { EN=0; // enable 595 MR=0; // reset thanh ghi MR=1; while(1) { quet(m[k]); k++; if(k==8) k=0; delay(2000); SCL=0; // chot dua du lieu ra 595 SCL=1; MR=0; // reset thanh ghi MR=1; } }
Comment