你好 貴司CH423 樣品已經(jīng)收到 用網(wǎng)站源碼下載程序 全部顯示8和小數(shù)點(diǎn) 并伴有閃爍 看不清數(shù)字 不知道什么原因 還有一點(diǎn) 關(guān)閉電源后再開啟電源 數(shù)碼管沒有任何顯示了 必須重新進(jìn)行ISP下載 才會出現(xiàn)全顯示8和小數(shù)點(diǎn) 開始閃爍 單片機(jī)AMEGA16L GCCAVR環(huán)境 不知道怎么會出現(xiàn)這個(gè)問題 急 望解決! 福州昌華動(dòng)力 小任
晶振為高速4M外部晶振 //本例子程序提供操作方法,僅供參考 // ******************************************************************* // Website: http://wch.cn // Email: tech@wch.cn // Author: TECH 2008.11.25 // *******************************************************************
//ATMEGA16 PC0 ------- CH423 SCL //ATMEGA16 PC1 ------- CH423 SDA
//ICCAVR下編譯
// ************************************** // 加載頭文件 // ************************************** #include
// ************************************** // CH423定義 // ************************************** #define CH423_SDA_OUT { DDRD |= (1<#define CH423_SDA_IN { PORTD |= (1<#define CH423_SDA_SET PORTD |= (1<#define CH423_SDA_CLR PORTD&=~(1<#define CH423_SDA ( PIND & (1<#define CH423_SCL_OUT { PORTD |= (1<#define CH423_SCL_SET PORTD |= (1<#define CH423_SCL_CLR PORTD &= ~(1<#define DELAY { asm("nop"); asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");}
// ************************************** // 延時(shí)毫秒,不準(zhǔn) // ************************************** void mDelaymS( unsigned int ms ) // 延時(shí)毫秒,不準(zhǔn) { unsigned int i; while ( ms -- ) { for( i = 0; i != 3000; i++ ); } }
// ************************************** // BCD碼表 // ************************************** const unsigned int BCD_decode_tab[ 29 ] = { 0X3F, 0X06, 0X5B, 0X4F, 0X66, 0X6D, 0X7D, 0X07, 0X7F, 0X6F, 0X77, 0X7C, 0X58, 0X5E, 0X79, 0X71, 0x00, 0x46, 0x40, 0x41, 0x39, 0x0F, 0x08, 0x76, 0x38, 0x73, 0x80, 0xFF, 0x00 };
// ************************************** // I2C START // ************************************** void CH423_I2c_Start( void ) { CH423_SDA_SET; /*發(fā)送起始條件的數(shù)據(jù)信號*/ CH423_SDA_OUT; /* 設(shè)置SDA為輸出方向 */ DELAY; CH423_SCL_SET;/* 設(shè)置SCL為輸出方向 */ DELAY; CH423_SDA_CLR; /*發(fā)送起始信號*/ DELAY; CH423_SCL_CLR; /*鉗住I2C總線,準(zhǔn)備發(fā)送或接收數(shù)據(jù) */ DELAY; }
// ************************************** // I2C STOP // ************************************** void CH423_I2c_Stop( void ) { CH423_SDA_CLR; CH423_SDA_OUT; /* 設(shè)置SDA為輸出方向 */ DELAY; CH423_SCL_SET; DELAY; CH423_SDA_SET; /*發(fā)送I2C總線結(jié)束信號*/ DELAY; CH423_SDA_IN; /* 設(shè)置SDA為輸入方向 */ DELAY; }
// ************************************** // I2C 寫一個(gè)字節(jié) // ************************************** void CH423_I2c_WrByte( unsigned int c ) //寫一個(gè)字節(jié)數(shù)據(jù) { unsigned int i; CH423_SDA_SET; CH423_SDA_OUT; /* 設(shè)置SDA為輸出方向 */ DELAY; for( i = 0; i != 8; i++ ) { if( c & 0x80 ) { CH423_SDA_SET; } else { CH423_SDA_CLR; } DELAY; CH423_SCL_SET; c <<= 1; DELAY; CH423_SCL_CLR; } CH423_SDA_IN; /* 設(shè)置SDA為輸入方向 */ DELAY; CH423_SCL_SET; DELAY; CH423_SCL_CLR; DELAY; }
// ************************************** // I2C 讀一個(gè)字節(jié) // ************************************** unsigned int CH423_I2c_RdByte( void ) //讀一個(gè)字節(jié)數(shù)據(jù) { unsigned int c, i; CH423_SDA_IN; /* 設(shè)置SDA為輸入方向 */ c = 0; for( i = 0; i != 8; i++ ) // 輸入8位數(shù)據(jù) { CH423_SCL_SET; DELAY; c <<= 1; if( CH423_SDA ) c++; // 輸入1位 CH423_SCL_CLR; DELAY; } CH423_SDA_SET; CH423_SDA_OUT; CH423_SCL_SET; // 發(fā)出無效應(yīng)答 DELAY; CH423_SCL_CLR; DELAY; return(c); }
// ************************************** // CH423寫命令 // ************************************** void CH423_Write( unsigned int command ) //寫命令 { CH423_I2c_Start(); /*啟動(dòng)總線*/ CH423_I2c_WrByte( (unsigned int)(command>>8) ); CH423_I2c_WrByte( (unsigned int)command ); /*發(fā)送數(shù)據(jù)*/ CH423_I2c_Stop(); /*結(jié)束總線*/ }
// ************************************** // CH423初始化 // ************************************** void CH423_Init( void ) { CH423_SCL_OUT; CH423_SDA_SET; CH423_SDA_OUT; }
void Clear( void )//清除顯示 { CH423_Write( 0x6000 ); CH423_Write( 0x6200 ); CH423_Write( 0x6400 ); CH423_Write( 0x6600 ); CH423_Write( 0x6800 ); CH423_Write( 0x6A00 ); CH423_Write( 0x6C00 ); CH423_Write( 0x6E00 ); CH423_Write( 0x7000 ); CH423_Write( 0x7200 ); CH423_Write( 0x7400 ); CH423_Write( 0x7600 ); CH423_Write( 0x7800 ); CH423_Write( 0x7A00 ); CH423_Write( 0x7C00 ); CH423_Write( 0x7E00 ); }
// ************************************** // 主函數(shù) // ************************************** int main( void ) { unsigned int count = 0; unsigned int dot = 0; unsigned int val; PORTD=0xFF; DDRD=0xFF; CH423_Init(); CH423_Write( 0x4800 | 0x17 );//啟用數(shù)碼管自動(dòng)掃描功能 Clear();//清除顯示
while(1) { val = BCD_decode_tab[count] | dot; CH423_Write( 0x6000 | val ); //16位數(shù)碼管顯示 CH423_Write( 0x6200 | val ); CH423_Write( 0x6400 | val ); CH423_Write( 0x6600 | val ); CH423_Write( 0x6800 | val ); CH423_Write( 0x6A00 | val ); CH423_Write( 0x6C00 | val ); CH423_Write( 0x6E00 | val ); CH423_Write( 0x7000 | val ); CH423_Write( 0x7200 | val ); CH423_Write( 0x7400 | val ); CH423_Write( 0x7600 | val ); CH423_Write( 0x7800 | val ); CH423_Write( 0x7A00 | val ); CH423_Write( 0x7C00 | val ); CH423_Write( 0x7E00 | val ); if( count != 15 ) count++; else { count = 0; if( dot == 0 ) dot = 0x80; else dot = 0; } mDelaymS( 250); mDelaymS( 250); }
}
SORRY 是我太粗心了 GCCAVR不支持for( i = 0; i != 3000; i++ );這樣寫 原來 改為如下 就OK for( i = 0; i != 3000; i++ )asm("nop"); 可以顯示0-F了 但是 關(guān)掉電源再開電源 數(shù)碼管沒有任何顯示 不知道為何 必須重新下載程序 一次 才又顯示
個(gè)人認(rèn)為是不是CH423啟動(dòng)時(shí)間比單片機(jī)要長 所以改了單片機(jī)的啟動(dòng)延時(shí) 問題解決了 謝謝 也許還有問題 到時(shí)候望指教了
您好,CH423是內(nèi)置了上電復(fù)位電路,由電源檢測產(chǎn)生的復(fù)位時(shí)間大約為30Ms,所以在發(fā)送CH423命令之前要加上電延遲。