BASIC4MCU | 질문게시판 | 답변 : Codevision소스로 변환
페이지 정보
작성자 master 작성일2018-12-14 16:53 조회5,730회 댓글0건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=6880
본문
// MCU BASIC: https://www.basic4mcu.com// DateTime : 2018-12-14 오후 4:58:35// by Ok-Hyun Park//#include <mega128.h>#include <delay.h>//char sec_num[]="20021282"; //비밀번호char key_IN[8];int arr_cnt=1,right=1,g=0,s=0,i=0;//----------------------------------------------------void LCD_CMD(char b){PORTA=(b&0xF0)|4; delay_us(1); PORTA.2=0;PORTA=(b<<0x4)|4; delay_us(1); PORTA.2=0; delay_ms(3);}//void LCD_Char(char b){PORTA=(b&0xF0)|5; delay_us(1); PORTA.2=0;PORTA=(b<<0x4)|5; delay_us(1); PORTA.2=0; delay_us(50);}//void LCD_Str(char b,char *s){ LCD_CMD(b); while(*s)LCD_Char(*s++); }//void init_LCD(void){DDRA=0xFF; delay_ms(30); LCD_CMD(0x28); LCD_CMD(0x28);LCD_CMD(0x0C); LCD_CMD(6); LCD_CMD(2); LCD_CMD(1);}//----------------------------------------------------// 키스캔 함수//----------------------------------------------------char Key(void){PORTC=0x01; delay_us(1);if (PINC.4)return 0x30; // 0else if(PINC.5)return 0x34; // 4else if(PINC.6)return 0x38; // 8else if(PINC.7)return 0x41; // APORTC=0x02; delay_us(1);if (PINC.4)return 0x31; // 1else if(PINC.5)return 0x35; // 5else if(PINC.6)return 0x39; // 9else if(PINC.7)return 0x42; // BPORTC=0x04; delay_us(1);if (PINC.4)return 0x32; // 2else if(PINC.5)return 0x36; // 6else if(PINC.6)return 0x2a; // *else if(PINC.7)return 0x43; // CPORTC=0x08; delay_us(1);if (PINC.4)return 0x33; // 3else if(PINC.5)return 0x37; // 7else if(PINC.6)return 0x23; // #else if(PINC.7)return 0x44; // D//return 0xff;}//----------------------------------------------------// 모터구동함수//----------------------------------------------------void dc_motor(char dir,unsigned int speed){if(dir)PORTB|=0x40; // 모터 방향 DIR(정방향)else PORTB&=0xBF; // 모터 방향 DIR(역방향)OCR1A=speed;}//----------------------------------------------------// 비밀번호 확인 함수//----------------------------------------------------void sec_test(char b){if(arr_cnt==8){for(g=0; g<8; g++){ if(key_IN[g]==sec_num[g])right++; }if(right==8){LCD_CMD(0x01); LCD_Str(0x80,"OPEN"); dc_motor(0,0x3ff); delay_ms(500); OCR1A=0;LCD_CMD(0x01); LCD_Str(0x80,"Password");}else{LCD_CMD(0x01); LCD_Str(0x80,"Retry"); delay_ms(500);LCD_CMD(0x01); LCD_Str(0x80,"Password");}arr_cnt=1; right=1; g=0; s=0; i=0;}else{ key_IN[s]=b; s++; arr_cnt++; }}//----------------------------------------------------interrupt[EXT_INT4]void ext_int4_isr(void){LCD_CMD(0x01); LCD_Str(0x80,"Password");dc_motor(1,0x3ff); delay_ms(1000); OCR1A=0;arr_cnt=1; right=1; g=0; s=0; i=0;EIFR|=0x10;}//----------------------------------------------------void main(void){char key=0xff;PORTB=0xFF; DDRB=0xE0;DDRC=0x0f;init_LCD(); LCD_Str(0x80,"Password");TCCR1A=0x83; TCCR1B=2; // Phase correct PWM 10bit,8 prescaler // f=997Hz,T=1.003msecEICRB=0x03; EIFR=0x10; EIMSK|=0x10;SREG=0x80;while(1){key=Key();if(key!=0xff){LCD_CMD(0xC0+i); LCD_Char(key); // 리턴 키 값을 출력하는 함수.delay_ms(500);i++;sec_test(key); //비밀번호 확인 함수}}}
댓글 0
조회수 5,730등록된 댓글이 없습니다.