BASIC4MCU | 질문게시판 | 답변 : 디버깅 오류가 있습니다 ㅜㅜ
페이지 정보
작성자 master 작성일2018-12-13 17:46 조회5,840회 댓글0건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=6830
본문
// MCU BASIC: https://www.basic4mcu.com// DateTime : 2018-12-13 오후 5:51:51// by Ok-Hyun Park//#include <avr/io.h>#include <avr/interrupt.h>#define F_CPU 16000000#include <util/delay.h>//#define KEY_DN 1#define EV_DN 2#define EV_UP 4#define EV_LONGDN 8#define EV_DBCLICK 16//#define MIN_TERM 8#define MAX_TERM 60#define _DEBOUNCE 60#define _LONG_HOLD 1000#define _DC_GAP 250//typedef struct key_tag_type{volatile char *INPORT;char pin;volatile int8_t key;volatile int8_t tmr;} key_tag;//static int8_t _debounce_ticks;static int8_t _long_hold_ticks;static int8_t _dc_gap_ticks;//모스부호,/ 0=null/1=./ 2=ㅡ /int A[4]={ 1,2,0,0 },B[4]={ 2,1,1,1 },C[4]={ 2,1,2,1 },D[4]={ 2,1,1,0 },E[4]={ 1,0,0,0 },F[4]={ 1,1,2,1 },G[4]={ 2,2,1,0 },H[4]={ 1,1,1,1 },I[4]={ 1,1,0,0 },J[4]={ 1,2,2,2 },K[4]={ 2,1,2,0 },L[4]={ 1,2,1,1 },M[4]={ 2,2,0,0 },N[4]={ 2,1,0,0 },O[4]={ 2,2,2,0 },P[4]={ 1,2,2,1 },Q[4]={ 2,2,1,2 },R[4]={ 1,2,1,0 },S[4]={ 1,1,1,0 },T[4]={ 2,0,0,0 },U[4]={ 1,1,2,0 },V[4]={ 1,1,1,2 },W[4]={ 1,2,2,0 },X[4]={ 2,1,1,2 },Y[4]={ 2,1,2,2 },Z[4]={ 2,2,1,1 };//int curr=0,num=1,chanel=0,morse[4];//void LCD_command(unsigned char command){PORTB=command; PORTD=0x00; PORTD=0x01; PORTD=0x00; _delay_us(50); PORTD=0x00;}//void LCD_data(unsigned char data){PORTB=data; PORTD=0x02; PORTD=0x03; PORTD=0x02; _delay_us(50); PORTD=0x00;}//void LCD_clear(){ LCD_command(0x01); _delay_ms(2); }//void LCD_initialize(void){PORTD=0x03; PORTD=0x02; _delay_ms(2);LCD_command(0x38); LCD_command(0x0c); LCD_command(0x06); LCD_clear();}//void LCD_string(unsigned char command,char *string){LCD_command(command);while(*string!='\0'){ LCD_data(*string); string++; }}//void char_position(char x,char y){unsigned char position;if(y>1)y=1;if(x>15)x=15;position=y?x+0xc0: x+0x80;LCD_command(position);}//void Port_init(void){DDRB=0xff;PORTB=0x00;DDRD=0xff;PORTD=0x00;}//void Port_Init(void){DDRE=0x00; //BUTTONPORTE=0x00;DDRF=0xff;PORTF=0x00;DDRB=0xff; //LCDPORTB=0x00;DDRD=0xff;PORTD=0x00;DDRF=0xff;PORTF=0x00;DDRE=0xff;}//char GetBN(void){if((PINE&0x01)==0){ return '1'; _delay_ms(100); while(PINE&0x01); _delay_ms(100); }if((PINE&0x02)==0){ return '2'; _delay_ms(100); while(PINE&0x02); _delay_ms(100); }if((PINE&0x04)==0){ _delay_ms(100); return '3'; _delay_ms(100); while(PINE&0x04); _delay_ms(100); }if((PINE&0x08)==0){ return '4'; _delay_ms(100); while(PINE&0x08); _delay_ms(100); }if((PINE&0x10)==0){ return '5'; _delay_ms(100); while(PINE&0x10); _delay_ms(100); }if((PINE&0x20)==0){ return '6'; _delay_ms(100); while(PINE&0x20); _delay_ms(100); }return '0';}//void spelling(char arr){char arr1=arr+65;switch(arr1){case'A': LCD_string(0x8f,"A"); break;case'B': LCD_string(0x8f,"B"); break;case'C': LCD_string(0x8f,"C"); break;case'D': LCD_string(0x8f,"D"); break;case'E': LCD_string(0x8f,"E"); break;case'F': LCD_string(0x8f,"F"); break;case'G': LCD_string(0x8f,"G"); break;case'H': LCD_string(0x8f,"H"); break;case'I': LCD_string(0x8f,"I"); break;case'J': LCD_string(0x8f,"J"); break;case'K': LCD_string(0x8f,"K"); break;case'L': LCD_string(0x8f,"L"); break;case'M': LCD_string(0x8f,"M"); break;case'N': LCD_string(0x8f,"N"); break;case'O': LCD_string(0x8f,"O"); break;case'P': LCD_string(0x8f,"P"); break;case'Q': LCD_string(0x8f,"Q"); break;case'R': LCD_string(0x8f,"R"); break;case'S': LCD_string(0x8f,"S"); break;case'T': LCD_string(0x8f,"T"); break;case'U': LCD_string(0x8f,"U"); break;case'V': LCD_string(0x8f,"V"); break;case'W': LCD_string(0x8f,"W"); break;case'X': LCD_string(0x8f,"X"); break;case'Y': LCD_string(0x8f,"Y"); break;case'Z': LCD_string(0x8f,"Z"); break;}}//void Eng(void){LCD_clear();LCD_string(0x80,"Enter Message"); LCD_string(0x8f,"?");char spell[]={ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"};int i=0;char Strings[20];int j=0;int force=0;while(chanel==1){//스펠링이 들어갈 곳.char btn=GetBN();//force=0;switch(btn){case '1': if(i== 0){ i=26; } i--; spelling(i); if(force<3){ _delay_ms(500); force++; } else{ _delay_ms(200); } break;case '2': if(i==25){ i=-1; } i++; spelling(i); if(force<3){ _delay_ms(500); force++; } else{ _delay_ms(200); } break;case '3': Strings[j]=spell[i]; j++; LCD_string(0xc0,Strings); _delay_ms(1000); break;case '5': for(int k=0; k<26; k++)Strings[k]=' '; j=0; LCD_string(0xc0,Strings); break;case '6': chanel=0; break;} //switch} //while}//void EGtoMS(void){ _delay_ms(500);chanel=1;LCD_clear();// LCD_command(0x0e);Eng();}//void test(void){char test='A';switch(test){case 'A': LCD_string(0x8f,"A"); break;}}//void hook_key(key_tag *k){if(k->tmr>0){if(k->tmr<_debounce_ticks)k->tmr++;else{if((*(k->INPORT)&k->pin)!=0){ k->key&=~KEY_DN; k->key|=EV_UP; k->tmr=-1; }else{if(k->tmr<_long_hold_ticks){ k->tmr++; if(k->tmr==_long_hold_ticks)k->key|=EV_LONGDN; }}}}else if(k->tmr<0){if(-k->tmr<_debounce_ticks)k->tmr--;else{if(((*k->INPORT)&(k->pin))==0){if(-k->tmr<_dc_gap_ticks)k->key|=EV_DBCLICK;k->key|=(KEY_DN|EV_DN);k->tmr=1;}else{ if(k->tmr<_dc_gap_ticks)k->tmr--; }}}else{if((*(k->INPORT)&k->pin)!=0){ k->key=0; k->tmr=-_dc_gap_ticks; }else{ k->key=KEY_DN; k->tmr=1; }}}//int8_t getEV(key_tag *k){int8_t c;cli();c=k->key;k->key&=KEY_DN;sei();return c;}///*void init_key(key_tag *k,volatile char *PORTE,int8_t pin_num,uint8_t term){*((volatile char*)(PORTE-1))&=~_BV(pin_num);k->INPORT=(volatile char*)(PORTE-2);k->pin=_BV(pin_num);if (term<MIN_TERM)term=MIN_TERM;else if(term>MAX_TERM)term=MAX_TERM;_debounce_ticks=(_DEBOUNCE/term);_long_hold_ticks=(_LONG_HOLD/term);}*///int main(void){char sceneNo='0',sceneNo0='0';Port_init();_delay_ms(50); //cacheLCD_initialize();LCD_clear();_delay_ms(10);//main stageLCD_string(0x80,"1.ENG to MORSE");LCD_string(0xc0,"2.MORto ENG Ini2");while(chanel==0){//get a button mainsceneNo=GetBN();if(sceneNo==sceneNo0)continue;switch(sceneNo){case '1': LCD_string(0x80,"--ch0ch0"); break;case '2': LCD_string(0x80,"ch0ch0ch0"); break;case '3': LCD_clear(); EGtoMS(); break;case '6': LCD_clear(); LCD_string(0x80,"1.ENG to MORSE"); LCD_string(0xc0,"2.MORto ENG Home"); break;}} //whilereturn 0;} //main
댓글 0
조회수 5,840등록된 댓글이 없습니다.