求救:CH452按鍵沒反應(yīng),請幫忙!

電路圖如下:

UploadImages/dounal20061016102139.rar

選用的CPU是ATMEGA32,PC0--SCL,PC1--SDA,RST--RST,INT0--INT0 各位高手能否給我一個測試程序?現(xiàn)在顯示沒問題,就是無法識別按鍵!

首先你有沒有開鍵盤,其次就是你開了鍵盤之后,你的鍵按下去之后中斷腳有沒有拉低?


發(fā)現(xiàn)能夠產(chǎn)生中斷,我在中斷里面放了一個顯示的函數(shù),發(fā)現(xiàn)按下按鍵,能指示已經(jīng)發(fā)生中斷,現(xiàn)在的問題就是用ATMEGA32的INT0中斷來讀取按鍵的函數(shù)有問題,我把讀取的按鍵值送到顯示,發(fā)現(xiàn)沒顯示,也就是說讀取的按鍵值始終為0x00。


/********************************************************************* ** - main program file - ** Device: Atmega32 ** target: brt301 ** freq : 7.3728MHz ** Vesion: 1.0 ** Editor: dounal ** Revise date: 2006-09-15 ** Copyright by Beijing brt co.,ltd ** 2006. All rights reserved. ***********************************************************/ #include "iom32v.h" #include "macros.h"

#define CH452_NOP 0x0000 //空操作 #define CH452_RESET 0x0201 //復位 #define CH452_LEVEL 0x0100 //加載光柱值 #define CH452_CLR_BIT 0x0180 //段位清0 #define CH452_SET_BIT 0x01C0 //段位置1 #define CH452_SLEEP 0x0202 //進入睡眠狀態(tài) #define CH452_LEFTMOV 0x0300 //設(shè)置移動方式-作移 #define CH452_LEFTCYC 0x0301 //設(shè)置移動方式-左循 #define CH452_RIGHTMOV 0x0302 //設(shè)置移動方式-右移 #define CH452_RIGHTCYC 0x0303 //設(shè)置移動方式-右循 #define CH452_SELF_BCD 0x0380 //自定義BCD碼 #define CH452_SYSOFF 0x0400 //關(guān)顯示、鍵盤 #define CH452_SYSON1 0x0401 //開顯示 #define CH452_SYSON2 0x0403 //開顯示、鍵盤 #define CH452_SYSON2W 0x0423 //開顯示、鍵盤, 真正2線接口 #define CH452_DSP 0x0500 //設(shè)置默認顯示方式 #define CH452_BCD 0x0580 //設(shè)置BCD譯碼方式 #define CH452_TWINKLE 0x0600 //設(shè)置閃爍控制 #define CH452_GET_KEY 0x0700 //獲取按鍵 #define CH452_DIG0 0x0800 //數(shù)碼管位0顯示 #define CH452_DIG1 0x0900 //數(shù)碼管位1顯示 #define CH452_DIG2 0x0a00 //數(shù)碼管位2顯示 #define CH452_DIG3 0x0b00 //數(shù)碼管位3顯示 #define CH452_DIG4 0x0c00 //數(shù)碼管位4顯示 #define CH452_DIG5 0x0d00 //數(shù)碼管位5顯示 #define CH452_DIG6 0x0e00 //數(shù)碼管位6顯示 #define CH452_DIG7 0x0f00 //數(shù)碼管位7顯示

#define CH452_SDA PINC1

#define SET_BIT(x,y) (x|=(1<#define CLR_BIT(x,y) (x&=~(1<#define GET_BIT(x,y) (x&(1<#define CH452_SCL_SET (PORTC|=0X01) #define CH452_SCL_CLR (PORTC&=0XFE) #define CH452_SDA_SET (PORTC|=0X02) #define CH452_SDA_CLR (PORTC&=0XFD) #define CLEAR_INTER_FLAG (GIFR&=0xBF) //************************************************************************** unsigned char good_display_seg[5]={0x00,0x6f,0x5c,0x5c,0x5e}; unsigned char all_display_seg[5]={0x77,0x38,0xb8,0x00,0x3f}; unsigned char off1_display_seg[5]={0x3f,0x40,0x5c,0x71,0x71}; unsigned char on1_display_seg[5]={0x3f,0x40,0x5c,0x54,0x00}; unsigned char err_display_seg[4]={0x79,0x50,0x50,0x00}; unsigned char uload_display_seg[5]={0x3e,0x38,0x5c,0x77,0x5e}; unsigned char dload_display_seg[5]={0x5e,0x38,0x5c,0x77,0x5e}; unsigned char eng_display_seg[5]={0x00,0x00,0x79,0x54,0x6f}; unsigned char deeng_display_seg[5]={0x5e,0x79,0x79,0x54,0x6f}; unsigned char off_display_seg[5]={0x00,0x00,0x5c,0x71,0x71}; unsigned char gros_display_seg[5]={0x00,0x6f,0x50,0x5c,0x6d}; unsigned char net_display_seg[5]={0x00,0x00,0x54,0x79,0x78}; unsigned char num_display_seg[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7c,0x07,0x7f,0x67}; //************************************************************************** unsigned char disp_buff[6]; unsigned char disp_buff_temp[6]; unsigned char indicate_flag; unsigned char key_val_temp; unsigned char key_val;

void delay_ms(unsigned int ti); void delay_us(unsigned int ui); void display_init(void); void display_check(void); void CH452_I2c_Start(void); void CH452_I2c_Stop(void); void mcu_init(void); void CH452_I2c_WrByte(unsigned char c); unsigned char CH452_I2c_RdByte(void); void CH452_Write(unsigned short command); unsigned char CH452_Read(void); void disp_good(void);

void key_int(void); void TXD_int(void); void uart0_init(void); //*************************顯示程序********************************** //函數(shù)功能:void init_devices(void) //函數(shù)輸入: //函數(shù)輸出: //操作對象及參數(shù)說明: //************************************************************************ void display_init(void) { //CH452_Write(CH452_RESET); delay_us(30); CH452_Write(CH452_DSP); CH452_Write(CH452_SYSON2); CH452_Write(CH452_TWINKLE | 0x00); }

void delay_ms(unsigned int ti) { unsigned int tj; for(;ti!=0;ti--) { for (tj=1000;tj!=0;tj--) { ; } } } void delay_us(unsigned int ui) { for(;ui>0;ui--) { ; } } void CH452_I2c_Start(void) { CLR_BIT(GICR,INT0); //禁止鍵盤中斷,防止開始時被CH452中斷 //而進入中斷服務(wù)程序中的START CH452_SDA_SET; //發(fā)送起始條件的數(shù)據(jù)信號 CH452_SCL_SET; delay_us(1); CH452_SDA_CLR; //發(fā)送起始信號*/ delay_us(1); CH452_SCL_CLR; //鉗住I2C總線,準備發(fā)送或接收數(shù)據(jù) */ delay_us(1); } void CH452_I2c_Stop(void) { CH452_SDA_CLR; delay_us(1); CH452_SCL_SET; delay_us(1); CH452_SDA_SET; //發(fā)送I2C總線結(jié)束信號*/ delay_us(1); SET_BIT(GICR,INT0); }

void CH452_I2c_WrByte(unsigned char c) //寫一個字節(jié)數(shù)據(jù) { unsigned char i; for(i=0;i<8;i++) // 輸出8位數(shù)據(jù) { if(c&0x80) {CH452_SDA_SET;} else {CH452_SDA_CLR;} CH452_SCL_SET; c<<=1; delay_us(1); delay_us(1); CH452_SCL_CLR; delay_us(1); // DELAY_1US; delay_us(1); } delay_us(1); CH452_SDA_SET; CH452_SCL_SET; // 接收應(yīng)答 delay_us(1); delay_us(1); CH452_SCL_CLR; delay_us(1); delay_us(1); } unsigned char CH452_I2c_RdByte(void) //讀一個字節(jié)數(shù)據(jù) { unsigned char c,i; c=0; for(i=0;i!=8;i++) // 輸入8位數(shù)據(jù) { CH452_SDA_SET; CH452_SCL_SET; delay_us(1); delay_us(1); c<<=1; //delay_us(10); if(GET_BIT(PORTC,CH452_SDA)) c|=0x01; // 輸入1位 CH452_SCL_CLR; delay_us(1); delay_us(1); // DELAY_1US; } delay_us(1); CH452_SDA_SET; CH452_SCL_SET; // 發(fā)出無效應(yīng)答 delay_us(1); delay_us(1); CH452_SCL_CLR; delay_us(1); return(c); } void CH452_Write(unsigned short command) //寫命令 { CH452_I2c_Start(); //啟動總線*/ CH452_I2c_WrByte(((unsigned char)(command>>7)&0x3E)|0x60); // CH452的ADDR=1時(默認) CH452_I2c_WrByte((unsigned char)command); //發(fā)送數(shù)據(jù)*/ CH452_I2c_Stop(); //結(jié)束總線*/ } unsigned char CH452_Read(void) //讀取按鍵 { unsigned char key; CH452_I2c_Start(); /*啟動總線*/ CH452_I2c_WrByte(0x6F); // 若有兩個CH452并連,當ADDR=0時,此值為0x4F key=CH452_I2c_RdByte(); /*讀取數(shù)據(jù)*/ CH452_I2c_Stop(); /*結(jié)束總線*/ return(key); }

void display_check(void) { unsigned int i; unsigned char temp; for(i=0;i<10;i++) { temp=num_display_seg[i]; CH452_Write(CH452_DIG0 | 0x10); // 顯示字符 CH452_Write(CH452_DIG1 | 0x10); CH452_Write(CH452_DIG2 | 0xff); CH452_Write(CH452_DIG3 | temp); CH452_Write(CH452_DIG4 | temp); CH452_Write(CH452_DIG5 | temp); CH452_Write(CH452_DIG6 | temp); CH452_Write(CH452_DIG7 | temp); delay_ms(250); } delay_ms(50); disp_good(); delay_ms(250); } void disp_good(void) { unsigned char j; for(j=0;j<5;j++) { disp_buff[j]=good_display_seg[j]; } CH452_Write(CH452_DIG3 | disp_buff[4]); CH452_Write(CH452_DIG4 | disp_buff[3]); CH452_Write(CH452_DIG5 | disp_buff[2]); CH452_Write(CH452_DIG6 | disp_buff[1]); CH452_Write(CH452_DIG7 | disp_buff[0]); } void mcu_init() { /*端口初始化,配置輸入或輸出*/ unsigned char i; DDRA =(1< PORTA=0xff; DDRB =(1<


遇到相同的問題,我也沒有解決


程序中首先需要發(fā)開按鍵命令,讀取按鍵需要注意中斷口方向,讀取到按鍵后,CH451的中斷腳變高


我也遇到這樣的問題,在按鍵中斷中讀到的數(shù)為0x00,前輩們是怎樣解決的?小弟這里誠心求教!!!!


問題同上。用匯編寫的。誰能解答?


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

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