[求助]ch452不能显示。

我使用了CH452显示驱动芯片,单片机是用Mega16,却无法将LED数码管点亮.现想将源代码粘出来,请各位高手帮忙看一下问题出在什么地方? //ICC-AVR application builder : 2006-5-8 11:51:08 // Target : M16 // Crystal: 8.0000Mhz

#include #include

//I/O端口初始化程序 void port_init(void) { PORTA = 0x0F; DDRA = 0xF0; //PA0 DI0 //PA1 DI1 //PA2 DI2 //PA4 DO0 //PA5 DO1 //PA6 DO2 PORTB = 0xFF; DDRB = 0xB0; //PB4 DO SS //PB5 DO MOSI //PB6 DI MISO //PB7 DO SCK PORTC = 0xFF; //m103 output only DDRC = 0x00; PORTD = 0xFF; DDRD = 0x3A; //PD0 DI RXD //PD1 DO TXD //PD2 DI CH452_KEY INT0 //PD3 DO CH452_LOAD //PD4 DO CH452_DIN //PD5 DO CH452_DCLK }

//SPI initialisation // clock rate: 2000000hz void spi_init(void) { SPCR = 0xF0; //setup SPI SPSR = 0x00; //setup SPI }

//UART0 initialisation // desired baud rate: 38400 // actual: baud rate:38462 (0.2%) // char size: 8 bit // parity: Disabled void uart0_init(void) { UCSRB = 0x00; //disable while setting baud rate UCSRA = 0x00; UCSRC = 0x86; UBRRL = 0x00; //set baud rate lo UBRRH = 0x00; //set baud rate hi UCSRB = 0xD8; }

void init_devices(void) { //stop errant interrupts until set up CLI(); //disable all interrupts port_init(); spi_init(); uart0_init();

MCUCR = 0x00; GICR = 0x40; TIMSK = 0x00; //timer interrupt sources SEI(); //re-enable interrupts //all peripherals are now initialised }

//微秒级延时程序 void delay_us(unsigned int time) { do time--; while (time>1); }

//毫秒级延时程序 void delay_ms(unsigned int time) { while(time != 0) { delay_us(1000); time--; } }

void ch452spiwrt(unsigned int data) { //PD2 DI CH452_KEY INT0 //PD3 DO CH452_LOAD //PD4 DO CH452_DIN //PD5 DO CH452_DCLK char num,temp; for(num = 0;num < 12;num++) { if(num > 0) data >>= 1; temp = data & 0x0001; if(temp == 0) { PORTD = PORTD & 0xcf; delay_ms(2); PORTD |= 0x20; } else { PORTD |= 0x20; PORTD = PORTD | 0x10 & 0x1f; delay_ms(2); PORTD |= 0x20; } if(num == 11) { PORTD = PORTD & 0xf7; delay_ms(2); PORTD |= 0x08; } } delay_ms(2); }

void ch452spiset(void) { signed int setvol = 0x0401,disvol = 0x0500; signed int dig0 = 0x08ff,dig1 = 0x0900,dig2 = 0x0aff,dig3 = 0x0b00; signed int dig4 = 0x0cff,dig5 = 0x0dff,dig6 = 0x0e00,dig7 = 0x0fff; ch452spiwrt(dig0); ch452spiwrt(dig1); ch452spiwrt(dig2); ch452spiwrt(dig3); ch452spiwrt(dig4); ch452spiwrt(dig5); ch452spiwrt(dig6);

ch452spiwrt(setvol); ch452spiwrt(disvol); }

void main(void) { init_devices(); ch452spiset(); while(1) { PORTD = PORTD & 0xf7; delay_ms(2); PORTD |= 0x08; delay_ms(2); } } 不知道是硬件还是软件问题。

你在ch452spiset()函数里面是先写数据在开显示,这样是不能显示的,还有在你主程序中并没有显示的函数,所以就没办法显示了啊!你将你的ch452spiset()函数的 ch452spiwrt(setvol);ch452spiwrt(disvol);函数放到你写数据到452的函数前面去看可以不可以显示


已经试过了,也不行,才想办法是不是先将数据写进去,再开显示.所以两种办法都不行.我的主函数里不是调用了ch452spiset()函数吗,里面不是有ch452spiwrt(dig0); ch452spiwrt(dig1); ch452spiwrt(dig2); ch452spiwrt(dig3); ch452spiwrt(dig4); ch452spiwrt(dig5); ch452spiwrt(dig6); 写数据的命令吗?


有高人指点说是时序不对,请各位高手看一下,时序错在什么地方?


只有登录才能回复,可以选择微信账号登录