Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

program keypad 3x4 missing "(", help me fix the error

Status
Not open for further replies.

iv4n.wae

Newbie level 2
Newbie level 2
Joined
May 29, 2013
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,326
#include <mega32.h>

// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>
#include <delay.h>
#include <stdio.h>
#define KEYPAD D
#define KEYPAD_PORT PORT(KEYPAD)
#ifndef KEYPAD_H_
#define KEYPAD_DDR DDR(KEYPAD)

#define KEYPAD_PIN PIN(KEYPAD)

#define ADC_VREF_TYPE 0x00

// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}
// SPI functions
#include <spi.h>
uint8_t GetKeyPressed() // this is the eror, please fix it, thanks.
{

uint8_t r,c;

KEYPAD_PORT|= 0X0F;

for(c=0;c<3;

c++)

{

KEYPAD_DDR&=~(0X7F);

KEYPAD_DDR|=(0X40>>c);

for(r=0;r<4;r++)

{

if(!(KEYPAD_PIN & (0X08>>r)))

{

return (r*3+c);

}

}

}

return 0XFF;//Indicate No key pressed

}
void main(void)
{
// Declare your local variables here
//Wait for LCD To Start

_delay_loop_2(0);

//Now initialize the module

LCDInit(LS_NONE);

uint8_t key;
// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;

// Port B initialization
// Func7=In Func6=Out Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=0 State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x40;

// Port C initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
PORTC=0x00;
DDRC=0xFF;

// Port D initialization
// Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
PORTD=0x00;
DDRD=0xFF;

// 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: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 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: Timer 2 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: On
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x00;
SFIOR=0x00;

// ADC initialization
// ADC Clock frequency: 750,000 kHz
// ADC Voltage Reference: AREF pin
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x84;

// SPI initialization
// SPI Type: Slave
// SPI Clock Rate: 3000,000 kHz
// SPI Clock Phase: Cycle Half
// SPI Clock Polarity: Low
// SPI Data Order: MSB First
SPCR=0x40;
SPSR=0x00;
int main(void)
{
DDRB=0xFF;
lcd_init();

uint16_t password;
uint8_t f;
uint16_t newpassword;
if(ReadPassFromEEPROM()==25755)
{
//Password is blank so store a default password
WritePassToEEPROM(5050);
_delay_ms(400);
}

LCD_clear;
LINE1;
dis_cmd(0x84);
string("Drive");
_delay_ms(200);
// LCD module initialization
lcd_init(16);

while (1)
{
key=GetKeyPressed();

LCDWriteIntXY(0,0,key,3);

LCD_clear;
password= InputNumber("Enter Password");//Get the keycode of pressed key
if(password==ReadPassFromEEPROM())
{
LCD_clear;
string("Unlocked");
_delay_ms(100);

while(1) {
f=GetKeyPressed();
while(GetKeyPressed()==255)
{
_delay_loop_2(10);
}
if (f==2){

password=InputNumber("Old Password");
_delay_ms(1000);

if (password==ReadPassFromEEPROM())

{
newpassword=InputNumber("new");

string("ok");
WritePassToEEPROM(newpassword);
_delay_ms(300);
}


}

}
}


else
{
LCD_clear;
string("Wrong Password");
_delay_ms(1000);
}

}
}
};
}
 
Last edited:

Maybe if you told us what line the error occurs at....

Obviously, you've got a mis-matched parentheses pair. Just go back and verify each "(" has a matching ")".
 

thanks for help, but i try and still not work
 

I'm not a C programmer, but I THINK you might need "void" inside the parentheses where you declare the function if you're not passing a variable into GetKeyPressed. Also, I think that declaration needs to be BEFORE any other code, i.e., your "ReadADC" function.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top