BASIC4MCU | 통신 | 모스 | 하이퍼터미널 - 부저 출력
페이지 정보
작성자 키트 작성일2017-09-01 14:15 조회1,555회 댓글0건본문
하이퍼 터미널로 입력한 문자를 모스 부호로 부저 출력합니다.//#define F_CPU 16000000UL // 16 MHz#include#include#include//#define MR_1 PORTE|= 0x10#define MR_0 PORTE&=~0x10//char morse_tbl[36][6]={{3,3,3,3,3,0}, //0{1,3,3,3,3,0}, //1{1,1,3,3,3,0}, //2{1,1,1,3,3,0}, //3{1,1,1,1,3,0}, //4{1,1,1,1,1,0}, //5{3,1,1,1,1,0}, //6{3,3,1,1,1,0}, //7{3,3,3,1,1,0}, //8{3,3,3,3,1,0}, //9{1,3,0,0,0,0}, //a{3,1,1,1,0,0}, //b{3,1,3,1,0,0}, //c{3,1,1,0,0,0}, //d{1,0,0,0,0,0}, //e{1,1,3,1,0,0}, //f{3,3,1,0,0,0}, //g{1,1,1,1,0,0}, //h{1,1,0,0,0,0}, //i{1,3,3,3,0,0}, //j{3,1,3,0,0,0}, //k{1,3,1,1,0,0}, //l{3,3,0,0,0,0}, //m{3,1,0,0,0,0}, //n{3,3,3,0,0,0}, //o{1,3,3,1,0,0}, //p{3,3,1,3,0,0}, //q{1,3,1,0,0,0}, //r{1,1,1,0,0,0}, //s{3,0,0,0,0,0}, //t{1,1,3,0,0,0}, //u{1,1,1,3,0,0}, //v{1,3,3,0,0,0}, //w{3,1,1,3,0,0}, //x{3,1,3,3,0,0}, //y{3,3,1,1,0,0} //z}//int rx[4]={0,};int SEG[36]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x27,0x7F,0x67,0x77,0x7C,0x39,0x5E,0x79,0x71,0x3D,0x74,0x30,0x1E,0x75,0x38,0x15,0x37,0x3F,0x73,0x67,0x33,0x6D,0x78,0x3E,0x2E,0x2A,0x76,0x62,0x4B};int SELECT[4]={0x01,0x02,0x04,0x08};//void tx0_chr(char d){ while(!(UCSR0A&0x20)); UDR0=d; }//void dot(char d){char i;while(d--){for(i=0;i<26;i++){ MR_1; _delay_us(1136); MR_0; _delay_us(1136); }}}//void space(char s){char i;while(d--){ _delay_ms(60); }}//void morse_chr(char m){char i;for(i=0;i<5;i++){switch(morse_tbl[m][i]){case 1: dot(1); break;case 3: dot(3); break;default: space(3); return;}space(1);}space(2);}//int main(void){unsigned char ch,i;DDRC=0xFF;DDRE=0x10; //morse out buzzerDDRG=0xFF;UCSR0B=0x18; UBRR0L=8;while(1){if(UCSR0A&0x80){ch=UDR0; tx0_chr(ch);if ((ch>='0')&&(ch<='9'))ch=ch-'0';else if((ch>='A')&&(ch<='Z'))ch=ch-'A'+10;else if((ch>='a')&&(ch<='z'))ch=ch-'a'+10;else ch=0;rx[3]=rx[2]; rx[2]=rx[1]; rx[1]=rx[0]; rx[0]=ch;morse_chr(ch);}for(i=0;i<4;i++){PORTG=SELECT[i]; PORTC=SEG[rx[i]]; _delay_ms(1);}}}부저는 발진회로 없는 모델을 사용해야 합니다.동작 시켜본 것은 아니니 버그가 있을 수 있습니다.덧글로 적어주세요
댓글 0
조회수 1,555등록된 댓글이 없습니다.