통신 > 하이퍼터미널 - 부저 출력 (스페이스 문자 추가)

TODAY483 TOTAL2,679,190
사이트 이용안내
Login▼/회원가입
최신글보기 질문게시판 기술자료 동영상강좌

아두이노 센서 ATMEGA128 PWM LED 초음파 AVR 블루투스 LCD UART 모터 적외선


BASIC4MCU | 통신 | 모스 | 하이퍼터미널 - 부저 출력 (스페이스 문자 추가)

페이지 정보

작성자 키트 작성일2017-09-01 14:15 조회1,277회 댓글0건

본문

//
#define F_CPU 16000000UL // 16 MHz
#include <avr/io.h> 
#include <util/delay.h> 
#include <avr/interrupt.h> 
//  
#define MR_1 PORTE|= 0x10
#define MR_0 PORTE&=~0x10
//
char morse_tbl[37][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
    {4,0,0,0,0,0}  //' ' 스페이스문자
}
//
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; 
         case  4: space(4); break; //' ' 스페이스문자
         default: space(3); return; 
      }
      space(1);
   }
   space(2);
}
//
int main(void){ 
   unsigned char ch,i; 
   DDRC=0xFF;
   DDRE=0x10; //morse out buzzer
   DDRG=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 if(ch==' ')ch=36; //' ' 스페이스문자
         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,277

등록된 댓글이 없습니다.

통신HOME > 통신 > 모스 목록

게시물 검색

2022년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2021년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2020년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2019년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
2018년 1월 2월 3월 4월 5월 6월 7월 8월 9월 10월 11월 12월
Privacy Policy
MCU BASIC ⓒ 2020
모바일버전으로보기