求救:CH452按键没反应,请帮忙!

电路图如下:

UploadImages/dounal20061016102139.rar

选用的CPU是ATMEGA32,PC0--SCL,PC1--SDA,RST--RST,INT0--INT0 各位高手能否给我一个测试程序?现在显示没问题,就是无法识别按键!

首先你有没有开键盘,其次就是你开了键盘之后,你的键按下去之后中断脚有没有拉低?


发现能够产生中断,我在中断里面放了一个显示的函数,发现按下按键,能指示已经发生中断,现在的问题就是用ATMEGA32的INT0中断来读取按键的函数有问题,我把读取的按键值送到显示,发现没显示,也就是说读取的按键值始终为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 //进入睡眠状态 #define CH452_LEFTMOV 0x0300 //设置移动方式-作移 #define CH452_LEFTCYC 0x0301 //设置移动方式-左循 #define CH452_RIGHTMOV 0x0302 //设置移动方式-右移 #define CH452_RIGHTCYC 0x0303 //设置移动方式-右循 #define CH452_SELF_BCD 0x0380 //自定义BCD码 #define CH452_SYSOFF 0x0400 //关显示、键盘 #define CH452_SYSON1 0x0401 //开显示 #define CH452_SYSON2 0x0403 //开显示、键盘 #define CH452_SYSON2W 0x0423 //开显示、键盘, 真正2线接口 #define CH452_DSP 0x0500 //设置默认显示方式 #define CH452_BCD 0x0580 //设置BCD译码方式 #define CH452_TWINKLE 0x0600 //设置闪烁控制 #define CH452_GET_KEY 0x0700 //获取按键 #define CH452_DIG0 0x0800 //数码管位0显示 #define CH452_DIG1 0x0900 //数码管位1显示 #define CH452_DIG2 0x0a00 //数码管位2显示 #define CH452_DIG3 0x0b00 //数码管位3显示 #define CH452_DIG4 0x0c00 //数码管位4显示 #define CH452_DIG5 0x0d00 //数码管位5显示 #define CH452_DIG6 0x0e00 //数码管位6显示 #define CH452_DIG7 0x0f00 //数码管位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); //*************************显示程序********************************** //函数功能:void init_devices(void) //函数输入: //函数输出: //操作对象及参数说明: //************************************************************************ 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中断 //而进入中断服务程序中的START CH452_SDA_SET; //发送起始条件的数据信号 CH452_SCL_SET; delay_us(1); CH452_SDA_CLR; //发送起始信号*/ delay_us(1); CH452_SCL_CLR; //钳住I2C总线,准备发送或接收数据 */ delay_us(1); } void CH452_I2c_Stop(void) { CH452_SDA_CLR; delay_us(1); CH452_SCL_SET; delay_us(1); CH452_SDA_SET; //发送I2C总线结束信号*/ delay_us(1); SET_BIT(GICR,INT0); }

void CH452_I2c_WrByte(unsigned char c) //写一个字节数据 { unsigned char i; for(i=0;i<8;i++) // 输出8位数据 { 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; // 接收应答 delay_us(1); delay_us(1); CH452_SCL_CLR; delay_us(1); delay_us(1); } unsigned char CH452_I2c_RdByte(void) //读一个字节数据 { unsigned char c,i; c=0; for(i=0;i!=8;i++) // 输入8位数据 { 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; // 发出无效应答 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); //发送数据*/ CH452_I2c_Stop(); //结束总线*/ } unsigned char CH452_Read(void) //读取按键 { unsigned char key; CH452_I2c_Start(); /*启动总线*/ CH452_I2c_WrByte(0x6F); // 若有两个CH452并连,当ADDR=0时,此值为0x4F key=CH452_I2c_RdByte(); /*读取数据*/ CH452_I2c_Stop(); /*结束总线*/ 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<


遇到相同的问题,我也没有解决


程序中首先需要发开按键命令,读取按键需要注意中断口方向,读取到按键后,CH451的中断脚变高


我也遇到这样的问题,在按键中断中读到的数为0x00,前辈们是怎样解决的?小弟这里诚心求教!!!!


问题同上。用汇编写的。谁能解答?


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