哪位大蝦有實用的CH451驅(qū)動數(shù)碼管的程序,無私共享一下哦,^-^謝謝^-^,期待大蝦們能夠各展絕活
mega16驅(qū)動CH451 #include #define clk 4 //pd4 #define dat 3 //pd5 #define load 5 //pd6 #define load1 6 //pd7 #define XTAL 4 //晶振頻率,單位MHz #define uchar unsigned char /*******************************延時函數(shù)***********************************/ void delay_1us(void) //1us延時函數(shù) { asm("nop"); } void delay_nus(unsigned int n) //N us延時函數(shù) { unsigned int i="0"; for (i=0;i delay_1us(); } void delay_1ms(void) //1ms延時函數(shù) { unsigned int i; for (i=0;i<(unsigned int)(XTAL*143-2);i++); } void delay_nms(unsigned int n) //N ms延時函數(shù) { unsigned int i="0"; for (i=0;i { delay_1ms(); } } /*******************************451寫指令***********************************/ void write(long int x) { long int ch; int i; ch = x; PORTD&= ~(1< PORTD&= ~(1< for(i=0; i<12; i++) { if(ch&0x001) { PORTD|= 0x08; //數(shù)據(jù)為1 00100000 ch >>= 1; PORTD&= ~(1< PORTD|= (1< } else { PORTD&= ~(0x08); //數(shù)據(jù)為0 ch >>= 1; PORTD&= ~(1< PORTD|= (1< } } PORTD|= 1< } void write1(long int x) { long int ch; int i; ch = x; PORTD&= ~(1< PORTD&= ~(1< for(i=0; i<12; i++) { if(ch&0x001) { PORTD|= 0x08; //數(shù)據(jù)為1 00100000 ch >>= 1; PORTD&= ~(1< PORTD|= (1< } else { PORTD&= ~(0x08); //數(shù)據(jù)為0 ch >>= 1; PORTD&= ~(1< PORTD|= (1< } } PORTD|= 1< } /*******************************主函數(shù)***********************************/ int main( void ) { int i="0",n=0,m=0; DDRD=0xff; //設置為輸出 PORTD |=1< PORTD &=~(1< delay_nms(20); PORTD |=1< write(0x201); write(0x401); write(0x500); write1(0x201); write1(0x401); write1(0x500); while(1) { write(0x8ff); write1(0x8ff); write1(0x9ff); write1(0xaff); write1(0xbff); delay_nms(1000); } } /*******************************END***********************************/
期待大蝦們對本主題的支持...
您可以到我們的網(wǎng)站下載詳細資料 http://wch.cn/bbs/View.asp?S=103&I=28488
您可以到我們的網(wǎng)站下載詳細資料 http://wch.cn/bbs/View.asp?S=103&I=28488
好的,謝謝