[求助]ch452不能顯示。

我使用了CH452顯示驅動芯片,單片機是用Mega16,卻無法將LED數(shù)碼管點亮.現(xiàn)想將源代碼粘出來,請各位高手幫忙看一下問題出在什么地方? //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()函數(shù)里面是先寫數(shù)據(jù)在開顯示,這樣是不能顯示的,還有在你主程序中并沒有顯示的函數(shù),所以就沒辦法顯示了??!你將你的ch452spiset()函數(shù)的 ch452spiwrt(setvol);ch452spiwrt(disvol);函數(shù)放到你寫數(shù)據(jù)到452的函數(shù)前面去看可以不可以顯示


已經試過了,也不行,才想辦法是不是先將數(shù)據(jù)寫進去,再開顯示.所以兩種辦法都不行.我的主函數(shù)里不是調用了ch452spiset()函數(shù)嗎,里面不是有ch452spiwrt(dig0); ch452spiwrt(dig1); ch452spiwrt(dig2); ch452spiwrt(dig3); ch452spiwrt(dig4); ch452spiwrt(dig5); ch452spiwrt(dig6); 寫數(shù)據(jù)的命令嗎?


有高人指點說是時序不對,請各位高手看一下,時序錯在什么地方?


只有登錄才能回復,可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频