#include <mega128.h>
#include <delay.h> #define lcd_dt PORTB
#define lcd_en PORTC.6
#define lcd_rw PORTC.5
#define lcd_rs PORTC.4
#define SERVO_1 PORTA.0
#define INPUTVALUE unsigned int i;
unsigned char PW[6] = (/* 비밀번호 */);
unsigned int INPUTVALUE[6];
unsigned char setcnt = 0;
unsigned char keycnt = 0;
unsigned char value;
unsigned char keyvalue; void SERVO_CLS()
{
for(i=0;i<30;i++)
{
SERVO_1 = 1;
delay_ms(1.45);
SERVO_1 = 0;
delay_ms(18.55);
}
}
void SERVO_OPEN()
{
for(i=0;i<30;i++)
{
SERVO_1 = 1;
delay_ms(2.3);
SERVO_1 = 0;
delay_ms(17.7);
}
} #define pKEYPAD_OUT_A_HIGH PORTC |= 0x01
#define pKEYPAD_OUT_A_LOW PORTC &= 0xFE
#define pKEYPAD_OUT_B_HIGH PORTC |= 0x02
#define pKEYPAD_OUT_B_LOW PORTC &= 0xFD
#define pKEYPAD_OUT_C_HIGH PORTC |= 0x04
#define pKEYPAD_OUT_C_LOW PORTC &= 0xFB
#define pKEYPAD_IN (PINC>>4) char KeypadIn(void)
{
char d; pKEYPAD_OUT_A_LOW;
pKEYPAD_OUT_B_HIGH;
pKEYPAD_OUT_C_HIGH; d = pKEYPAD_IN;
d = pKEYPAD_IN;
d = pKEYPAD_IN;
d = pKEYPAD_IN;
d = pKEYPAD_IN; if(d==0x0E){
return '1';
}
if(d==0x0D){
return '4';
}
if(d==0x0B){
return '7';
}
if(d==0x07){
return '*';
}
pKEYPAD_OUT_A_HIGH;
pKEYPAD_OUT_B_LOW;
pKEYPAD_OUT_C_HIGH; d = pKEYPAD_IN;
d = pKEYPAD_IN;
d = pKEYPAD_IN;
d = pKEYPAD_IN;
d = pKEYPAD_IN; if(d==0x0E){
return '2';
}
if(d==0x0D){
return '5';
}
if(d==0x0B){
return '8';
}
if(d==0x07){
return '0';
}
pKEYPAD_OUT_A_HIGH;
pKEYPAD_OUT_B_HIGH;
pKEYPAD_OUT_C_LOW; d = pKEYPAD_IN;
d = pKEYPAD_IN;
d = pKEYPAD_IN;
d = pKEYPAD_IN;
d = pKEYPAD_IN;
if(d==0x0E){
return '3';
}
if(d==0x0D){
return '6';
}
if(d==0x0B){
return '9';
}
if(d==0x07){
return '#';
}
return ' ';
} void dsp_str(char n)
{
lcd_rs=1;
lcd_dt=n;
lcd_en=1;
delay_us(1);
lcd_en=0;
delay_us(50);
}
void dsp_cmd(char n)
{
lcd_rs=0;
lcd_dt=n;
lcd_en=1;
delay_us(1); lcd_en=0;
delay_us(50);
}
/*void dsp_num(char n)
{
dsp_str(n + 0x30);
}*/
void lcd_init() //16x2line
{
lcd_dt=0;
lcd_rw=0;
lcd_rs=0;
lcd_en=0;
delay_ms(10);
dsp_cmd(0x30); //8bit mode
delay_ms(5);
dsp_cmd(0x30);
delay_ms(1); dsp_cmd(0x30);
delay_ms(5);
dsp_cmd(0x38); //function set
dsp_cmd(0x0c); //display on/off
dsp_cmd(0x14); //cursor/display
dsp_cmd(0x06); //entry mode
dsp_cmd(0x01);
delay_ms(2); //display clear
}
char str01[]={ "Door lock system" };
char str02[]={ " PW : " };
void dsp_lcd()
{
dsp_cmd(0x80); //line1
for(i=0; i<16; ++i) dsp_str(str01[i]);
dsp_cmd(0xc0); //line2
for(i=0; i<6; ++i) dsp_str(str02[i]);
}
void pwcheck()
{
if((PW[0] ==INPUTVALUE[0])&&(PW[1]==INPUTVALUE[1])&&(PW[2]==INPUTVALUE[2])&&(PW[3]==INPUTVALUE[3])&&(PW[4]==INPUTVALUE[4])&&(PW[5]==INPUTVALUE[5]))
{
SERVO_OPEN();
keycnt=0;
dsp_cmd(0xc6);
for(i=0;i<6;i++)
{
INPUTVALUE[i]=' ';
dsp_str(INPUTVALUE[i]);
}
}
else
{
SERVO_CLS();
keycnt=0;
dsp_cmd(0xc6);
for(i=0;i<6;i++)
{
INPUTVALUE[i]=' ';
dsp_str(INPUTVALUE[i]);
}
}
} void key_check()
{
if(KeypadIn()== '*')
{
setcnt++;
keycnt=0;
dsp_cmd(0xc6);
for(i=0;i<6;i++)
{
INPUTVALUE[i]= ' ';
dsp_str(INPUTVALUE[i]);
}
if(setcnt>1) setcnt=0;
}
if(KeypadIn()== '#')
{
setcnt=0;
pwcheck();
}
pKEYPAD_OUT_A_LOW;
pKEYPAD_OUT_B_LOW;
pKEYPAD_OUT_C_LOW;
value = 0;
value = pKEYPAD_IN &0x0f;
if(setcnt==1)
{
if(value != 0x0f)?
{
PORTD=0x00;
keyvalue = KeypadIn();
if(( keyvalue != '*' ) &&( keyvalue != '#'))
{
keycnt++;
if(keycnt == 1)
{
INPUTVALUE[0] = KeypadIn();
dsp_cmd(0xc6);
dsp_str(INPUTVALUE[0]);
}
if(keycnt == 2)
{
INPUTVALUE[1] = KeypadIn();
dsp_cmd(0xc6);
dsp_str('*');
dsp_cmd(0xc7);
dsp_str(INPUTVALUE[1]);
}
if(keycnt == 3)
{
INPUTVALUE[2] = KeypadIn();
dsp_cmd(0xc7);
dsp_str('*');
dsp_cmd(0xc8);
dsp_str(INPUTVALUE[2]);
}
if(keycnt == 4)
{
INPUTVALUE[3] = KeypadIn();
dsp_cmd(0xc8);
dsp_str('*');
dsp_cmd(0xc9);
dsp_str(INPUTVALUE[3]);
}
if(keycnt == 5)
{
INPUTVALUE[4] = KeypadIn();
dsp_cmd(0xc9);
dsp_str('*');
dsp_cmd(0xca);
dsp_str(INPUTVALUE[4]);
}
if(keycnt == 6)
{
INPUTVALUE[5] = KeypadIn();
dsp_cmd(0xca);
dsp_str('*');
dsp_cmd(0xcb);
dsp_str(INPUTVALUE[5]); keycnt = 0;
}
}
value=0;
}
else PORTD=0xff;
}
delay_ms(150);
} void main()
{
DDRA=0xff;
DDRB=0xff;
DDRC=0x0f;
DDRB=0xff;
lcd_init();
dsp_lcd();
PORTB=0xff;
while(1) { //endless loop
key_check();
}
}
----------------------------------------------------------------------------------------------------------------------------------------------
위에 소스에서 12번째 줄에서 invalid expression 에러가 나는데 도통 모르겠어요
#include <delay.h> #define lcd_dt PORTB
#define lcd_en PORTC.6
#define lcd_rw PORTC.5
#define lcd_rs PORTC.4
#define SERVO_1 PORTA.0
#define INPUTVALUE unsigned int i;
unsigned char PW[6] = (/* 비밀번호 */);
unsigned int INPUTVALUE[6];
unsigned char setcnt = 0;
unsigned char keycnt = 0;
unsigned char value;
unsigned char keyvalue; void SERVO_CLS()
{
for(i=0;i<30;i++)
{
SERVO_1 = 1;
delay_ms(1.45);
SERVO_1 = 0;
delay_ms(18.55);
}
}
void SERVO_OPEN()
{
for(i=0;i<30;i++)
{
SERVO_1 = 1;
delay_ms(2.3);
SERVO_1 = 0;
delay_ms(17.7);
}
} #define pKEYPAD_OUT_A_HIGH PORTC |= 0x01
#define pKEYPAD_OUT_A_LOW PORTC &= 0xFE
#define pKEYPAD_OUT_B_HIGH PORTC |= 0x02
#define pKEYPAD_OUT_B_LOW PORTC &= 0xFD
#define pKEYPAD_OUT_C_HIGH PORTC |= 0x04
#define pKEYPAD_OUT_C_LOW PORTC &= 0xFB
#define pKEYPAD_IN (PINC>>4) char KeypadIn(void)
{
char d; pKEYPAD_OUT_A_LOW;
pKEYPAD_OUT_B_HIGH;
pKEYPAD_OUT_C_HIGH; d = pKEYPAD_IN;
d = pKEYPAD_IN;
d = pKEYPAD_IN;
d = pKEYPAD_IN;
d = pKEYPAD_IN; if(d==0x0E){
return '1';
}
if(d==0x0D){
return '4';
}
if(d==0x0B){
return '7';
}
if(d==0x07){
return '*';
}
pKEYPAD_OUT_A_HIGH;
pKEYPAD_OUT_B_LOW;
pKEYPAD_OUT_C_HIGH; d = pKEYPAD_IN;
d = pKEYPAD_IN;
d = pKEYPAD_IN;
d = pKEYPAD_IN;
d = pKEYPAD_IN; if(d==0x0E){
return '2';
}
if(d==0x0D){
return '5';
}
if(d==0x0B){
return '8';
}
if(d==0x07){
return '0';
}
pKEYPAD_OUT_A_HIGH;
pKEYPAD_OUT_B_HIGH;
pKEYPAD_OUT_C_LOW; d = pKEYPAD_IN;
d = pKEYPAD_IN;
d = pKEYPAD_IN;
d = pKEYPAD_IN;
d = pKEYPAD_IN;
if(d==0x0E){
return '3';
}
if(d==0x0D){
return '6';
}
if(d==0x0B){
return '9';
}
if(d==0x07){
return '#';
}
return ' ';
} void dsp_str(char n)
{
lcd_rs=1;
lcd_dt=n;
lcd_en=1;
delay_us(1);
lcd_en=0;
delay_us(50);
}
void dsp_cmd(char n)
{
lcd_rs=0;
lcd_dt=n;
lcd_en=1;
delay_us(1); lcd_en=0;
delay_us(50);
}
/*void dsp_num(char n)
{
dsp_str(n + 0x30);
}*/
void lcd_init() //16x2line
{
lcd_dt=0;
lcd_rw=0;
lcd_rs=0;
lcd_en=0;
delay_ms(10);
dsp_cmd(0x30); //8bit mode
delay_ms(5);
dsp_cmd(0x30);
delay_ms(1); dsp_cmd(0x30);
delay_ms(5);
dsp_cmd(0x38); //function set
dsp_cmd(0x0c); //display on/off
dsp_cmd(0x14); //cursor/display
dsp_cmd(0x06); //entry mode
dsp_cmd(0x01);
delay_ms(2); //display clear
}
char str01[]={ "Door lock system" };
char str02[]={ " PW : " };
void dsp_lcd()
{
dsp_cmd(0x80); //line1
for(i=0; i<16; ++i) dsp_str(str01[i]);
dsp_cmd(0xc0); //line2
for(i=0; i<6; ++i) dsp_str(str02[i]);
}
void pwcheck()
{
if((PW[0] ==INPUTVALUE[0])&&(PW[1]==INPUTVALUE[1])&&(PW[2]==INPUTVALUE[2])&&(PW[3]==INPUTVALUE[3])&&(PW[4]==INPUTVALUE[4])&&(PW[5]==INPUTVALUE[5]))
{
SERVO_OPEN();
keycnt=0;
dsp_cmd(0xc6);
for(i=0;i<6;i++)
{
INPUTVALUE[i]=' ';
dsp_str(INPUTVALUE[i]);
}
}
else
{
SERVO_CLS();
keycnt=0;
dsp_cmd(0xc6);
for(i=0;i<6;i++)
{
INPUTVALUE[i]=' ';
dsp_str(INPUTVALUE[i]);
}
}
} void key_check()
{
if(KeypadIn()== '*')
{
setcnt++;
keycnt=0;
dsp_cmd(0xc6);
for(i=0;i<6;i++)
{
INPUTVALUE[i]= ' ';
dsp_str(INPUTVALUE[i]);
}
if(setcnt>1) setcnt=0;
}
if(KeypadIn()== '#')
{
setcnt=0;
pwcheck();
}
pKEYPAD_OUT_A_LOW;
pKEYPAD_OUT_B_LOW;
pKEYPAD_OUT_C_LOW;
value = 0;
value = pKEYPAD_IN &0x0f;
if(setcnt==1)
{
if(value != 0x0f)?
{
PORTD=0x00;
keyvalue = KeypadIn();
if(( keyvalue != '*' ) &&( keyvalue != '#'))
{
keycnt++;
if(keycnt == 1)
{
INPUTVALUE[0] = KeypadIn();
dsp_cmd(0xc6);
dsp_str(INPUTVALUE[0]);
}
if(keycnt == 2)
{
INPUTVALUE[1] = KeypadIn();
dsp_cmd(0xc6);
dsp_str('*');
dsp_cmd(0xc7);
dsp_str(INPUTVALUE[1]);
}
if(keycnt == 3)
{
INPUTVALUE[2] = KeypadIn();
dsp_cmd(0xc7);
dsp_str('*');
dsp_cmd(0xc8);
dsp_str(INPUTVALUE[2]);
}
if(keycnt == 4)
{
INPUTVALUE[3] = KeypadIn();
dsp_cmd(0xc8);
dsp_str('*');
dsp_cmd(0xc9);
dsp_str(INPUTVALUE[3]);
}
if(keycnt == 5)
{
INPUTVALUE[4] = KeypadIn();
dsp_cmd(0xc9);
dsp_str('*');
dsp_cmd(0xca);
dsp_str(INPUTVALUE[4]);
}
if(keycnt == 6)
{
INPUTVALUE[5] = KeypadIn();
dsp_cmd(0xca);
dsp_str('*');
dsp_cmd(0xcb);
dsp_str(INPUTVALUE[5]); keycnt = 0;
}
}
value=0;
}
else PORTD=0xff;
}
delay_ms(150);
} void main()
{
DDRA=0xff;
DDRB=0xff;
DDRC=0x0f;
DDRB=0xff;
lcd_init();
dsp_lcd();
PORTB=0xff;
while(1) { //endless loop
key_check();
}
}
----------------------------------------------------------------------------------------------------------------------------------------------
위에 소스에서 12번째 줄에서 invalid expression 에러가 나는데 도통 모르겠어요
--> unsigned char PW[6] = "( )"; /* 비밀번호 */
-> unsigned char PW[6] = {/* 비밀번호 */};
이렇게 해주셔야 되지 싶은데요...
아마 배열초기화를 () 로 해주셔서 알수없는 표현이다 라고 에러 뜨는거 같네요..