哪位大虾有实用的CH451驱动数码管的程序,无私共享一下哦,^-^谢谢^-^,期待大虾们能够各展绝活
mega16驱动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 /*******************************延时函数***********************************/ void delay_1us(void) //1us延时函数 { asm("nop"); } void delay_nus(unsigned int n) //N us延时函数 { unsigned int i="0"; for (i=0;i delay_1us(); } void delay_1ms(void) //1ms延时函数 { unsigned int i; for (i=0;i<(unsigned int)(XTAL*143-2);i++); } void delay_nms(unsigned int n) //N ms延时函数 { 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; //数据为1 00100000 ch >>= 1; PORTD&= ~(1< PORTD|= (1< } else { PORTD&= ~(0x08); //数据为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; //数据为1 00100000 ch >>= 1; PORTD&= ~(1< PORTD|= (1< } else { PORTD&= ~(0x08); //数据为0 ch >>= 1; PORTD&= ~(1< PORTD|= (1< } } PORTD|= 1< } /*******************************主函数***********************************/ 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***********************************/
期待大虾们对本主题的支持...
您可以到我们的网站下载详细资料 http://wch.cn/bbs/View.asp?S=103&I=28488
您可以到我们的网站下载详细资料 http://wch.cn/bbs/View.asp?S=103&I=28488
好的,谢谢