Бьюсь второй день иникак. Требуется считать нажатия кнопок на клавиатуре например 3 и 9 и когда ввели вторую цифру, выводим на лсд 89, а переменной для дальнейшей работы присваеваем число 89.
Клавиатуру читает, однако чтото не проходит с выводом и присваеванием.
Компилятор cvavr ругается на строку с atoi. Пробовал через sscanf : sscanf (lcd_buffer, "%d", &first); но тоже не работает.
CODE
/*****************************************************
Chip type : ATmega32
Program type : Application
AVR Core Clock frequency: 12,000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 512
*****************************************************/
#include <mega32.h>
#include <string.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x1B;PORTA
#endasm
#include <lcd.h>
/* include the prototype for sprintf */
#include <stdio.h>
/* include the prototype for abs */
#include <stdlib.h>
/* include the prototypes for the delay functions */
#include <delay.h>
/* include the prototypes for the keyboard 4x4 functions */
#include <keyboard.h>
// Declare your global variables here
char lcd_buffer[20];
void main(void)
{
// Declare your local variables here
unsigned char isClickButton = 0;
char first = 0;
char second = 0;
unsigned char flag =0;
PORTA=0x00;
DDRA=0x00;
PORTB=0x00;
DDRB=0x00;
PORTC=0x00;
DDRC=0x00;
PORTD=0x00;
DDRD=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
/* initialize the Keyboard 4x4 Port D*/
KEYB_Init();
/* initialize the LCD, 2 rows by 16 columns */
lcd_init(16);
lcd_clear();
while(1)
{
_Bool ButtonClicked = PINC.4==0 || PINC.5==0 || PINC.6==0 || PINC.7==0;
KEYB_ScanKeyboard(); //сканируем клавиатуру
if (ButtonClicked && 1 != isClickButton)
{
flag++;
if (flag>250)
{
sprintf( lcd_buffer,"1st= %c",KEYB_GetKey() ); //#include <stdio.h>
first = atoi (KEYB_GetKey());
lcd_gotoxy( 0,0 );
lcd_puts( lcd_buffer );
flag=0;
isClickButton=1;
} //delay_ms(500);
}
if ( ButtonClicked && (1 == isClickButton) )
{ flag++;
if ( flag>250 )
{
sprintf( lcd_buffer,"2nd= %c",KEYB_GetKey() ); //#include <stdio.h>
first = atoi (KEYB_GetKey());
lcd_gotoxy( 0,1 );
lcd_puts( lcd_buffer );
isClickButton=2;
flag=0;
} //delay_ms(500);
}
if ( 2 == isClickButton )
{
char tos = first*10+second;
sprintf( lcd_buffer,"Tos= %d",tos ); //#include <stdio.h>
lcd_gotoxy( 9,1 );
lcd_puts( lcd_buffer );
isClickButton=0;
}
}; //while
} //main
Chip type : ATmega32
Program type : Application
AVR Core Clock frequency: 12,000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 512
*****************************************************/
#include <mega32.h>
#include <string.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x1B;PORTA
#endasm
#include <lcd.h>
/* include the prototype for sprintf */
#include <stdio.h>
/* include the prototype for abs */
#include <stdlib.h>
/* include the prototypes for the delay functions */
#include <delay.h>
/* include the prototypes for the keyboard 4x4 functions */
#include <keyboard.h>
// Declare your global variables here
char lcd_buffer[20];
void main(void)
{
// Declare your local variables here
unsigned char isClickButton = 0;
char first = 0;
char second = 0;
unsigned char flag =0;
PORTA=0x00;
DDRA=0x00;
PORTB=0x00;
DDRB=0x00;
PORTC=0x00;
DDRC=0x00;
PORTD=0x00;
DDRD=0x00;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
/* initialize the Keyboard 4x4 Port D*/
KEYB_Init();
/* initialize the LCD, 2 rows by 16 columns */
lcd_init(16);
lcd_clear();
while(1)
{
_Bool ButtonClicked = PINC.4==0 || PINC.5==0 || PINC.6==0 || PINC.7==0;
KEYB_ScanKeyboard(); //сканируем клавиатуру
if (ButtonClicked && 1 != isClickButton)
{
flag++;
if (flag>250)
{
sprintf( lcd_buffer,"1st= %c",KEYB_GetKey() ); //#include <stdio.h>
first = atoi (KEYB_GetKey());
lcd_gotoxy( 0,0 );
lcd_puts( lcd_buffer );
flag=0;
isClickButton=1;
} //delay_ms(500);
}
if ( ButtonClicked && (1 == isClickButton) )
{ flag++;
if ( flag>250 )
{
sprintf( lcd_buffer,"2nd= %c",KEYB_GetKey() ); //#include <stdio.h>
first = atoi (KEYB_GetKey());
lcd_gotoxy( 0,1 );
lcd_puts( lcd_buffer );
isClickButton=2;
flag=0;
} //delay_ms(500);
}
if ( 2 == isClickButton )
{
char tos = first*10+second;
sprintf( lcd_buffer,"Tos= %d",tos ); //#include <stdio.h>
lcd_gotoxy( 9,1 );
lcd_puts( lcd_buffer );
isClickButton=0;
}
}; //while
} //main