회원가입 ID/PW 찾기
AA

안녕하세요

컴퓨터 keyboard를 통해 led제어 를 usart통신으로하려합니다

그런데 하이퍼터미널까지는 했는데요

제어가 되지않습니다

그냥 불만 들어옵니다..

어떤 포트에는 불이 들어오지 않지만 어떤 포트에는 불이 들어옵니다

무엇이 잘못된건지몰라서 질문 올립니다

혹시 소스보시고 아시는분은 빨리 답변좀 해주세요ㅠ

 

 

 

 

 

#include <avr/io.h>
#include <avr/interrupt.h>
#include "d:/WinAVR-20100110/avr/include/avr/iom128.h"
#include <stdio.h>

void tx0Char(char message);
void tx1Char(char message);


//int putchar(char c);
//int getchar(void);
void port_init(void);
void uart0_init(void);
void uart1_init(void);
void init_devices(void);
void delay(int n);
static int Putchar(char c, FILE *stream);

static int Putchar(char c, FILE *stream)
{
 tx0Char(c);
    tx1Char(c);
 return 0;
     
}

/*
// printf 함수에서 사용할 putchar 에 UART0와 UART1으로
// 데이터를 보내도록 하였다.
int putchar(char c)
{
    tx0Char(c);
    tx1Char(c);
 return c;
}*/

// UART0 을 이용한 출력
void tx0Char(char message)
{
 while (((UCSR0A>>UDRE0)&0x01) == 0) ;  // UDRE, data register empty       
    UDR0 = message;
}

// UART1 을 이용한 출력
void tx1Char(char message)
{
 while (((UCSR1A>>UDRE1)&0x01) == 0) ;  // UDRE, data register empty       
    UDR1 = message;
}

void USART_Transmit(unsigned char data)
{
 /*wait for empty transmit buffer*/
 while(!(UCSR0A & (1<<UDRE)));

 /*put data into buffer, sends the data*/

 UDR0 = data;

}

unsigned char USART_Receive(void)
{
int toggle=1;

 char temp;
 int shift = 0;
 /*wait for data to be received*/

 while(!(UCSR0A & (1<<RXC)));

 /*Get and return received data from buffer*/
 temp = UDR0 & 0xff;

 return temp; 

}


void port_init(void)
{
 PORTA = 0x00;
 DDRA  = 0x83;//83
 PORTB = 0x00;
 DDRB  = 0x00;
 PORTC = 0x00; //m103 output only
 DDRC  = 0x00;
 PORTD = 0x00;
 DDRD  = 0x00;
 PORTE = 0x02;
 DDRE  = 0x00;
 PORTF = 0x00;
 DDRF  = 0xff;//ff
 PORTG = 0x00;
 DDRG  = 0x03;//03
}


//UART0 initialize
// desired baud rate: 9600
// actual: baud rate:9615 (0.2%)
// char size: 8 bit
// parity: Disabled
void uart0_init(void)
{
 UCSR0B = 0x00; //disable while setting baud rate
 UCSR0A = 0x00;
 UCSR0C = 0x06;
 UBRR0L = 0x67; //set baud rate lo
 UBRR0H = 0x00; //set baud rate hi
 UCSR0B = 0x18;
}

//UART1 initialize
// desired baud rate:9600
// actual baud rate:9615 (0.2%)
// char size: 8 bit
// parity: Disabled
void uart1_init(void)
{
 UCSR1B = 0x00; //disable while setting baud rate
 UCSR1A = 0x00;
 UCSR1C = 0x06;
// UBRR1L = 0x2F; //set baud rate lo 7.3728 MHz
// UBRR1L = 0x47; //set baud rate lo 11.0592 Mhz
 UBRR1L = 0x67; //set baud rate lo 16Mhz
 UBRR1H = 0x00; //set baud rate hi
 UCSR1B = 0x18;
}

//call this routine to initialize all peripherals
void init_devices(void)
{
 //stop errant interrupts until set up
 cli(); //disable all interrupts
 XDIV  = 0x00; //xtal divider
 XMCRA = 0x00; //external memory
 port_init();
 uart0_init();              // UART 0 초기화
 uart1_init();              // UART 1 초기화
 fdevopen(Putchar,0);  

 MCUCR = 0x00;
 EICRA = 0x00; //extended ext ints
 EICRB = 0x00; //extended ext ints
 EIMSK = 0x00;
 TIMSK = 0x00; //timer interrupt sources
 ETIMSK = 0x00; //extended timer interrupt sources
 sei(); //re-enable interrupts
 //all peripherals are now initialized
}


// 시간 지연 함수
void delay(int n)
{
 volatile int i,j;

 for(i=1;i<n;i++)
 {
     for(j=1;j<600;j++);
 }
}


int main (void)
{

 init_devices();

 volatile unsigned char receive = 0;
 
 //insert your functional code here...
 printf("\n\r\ntesting...\n\r");
 printf("printf 테스트 프로그램...\n\r");


  printf("1. LED_ON / OFF 제어(q,w)\n");
  printf("2. 커텐온오프(a,s)\n");
  printf("3. 보안 온오프(z,x)\n");
  printf(" : ");
 

 do
 {
  receive = USART_Receive();
  
  switch (receive)
  {
   case 'q' :
   
    PORTD = 0xff;
   
   break;

   case 'w' :    /*js :빠져서추가*/ 
    
    PORTD = 0x00;   

   break;


   case 'a' :
   
    PORTA =  PORTA  | 0x01;   // 0000 0001
   
    delay(100);
    
    PORTA = PORTA & 0xfe;
   break;

   case 's' :
    PORTA = PORTA | 0x02;    // 0000 0010

    delay(100);

    PORTA = PORTA & 0xfd;   // 1111 1101
   break;

   case 'z' :
   //  PORTA_temp = PORTA_temp | 0x04;        //   0000 0100
   PORTA = PORTA | 0x04;
   break;

   case 'x' :

   PORTA = PORTA & 0xfc;   // 1111 1011

   break;

   default : break;


  }

     }while(1);

 


 

 

 

 return 0;
}

댓글 1
  • No Profile

    이소스를 한가히 분석하고 답을 드리긴 쉽지않겠죠.. 기본적으로 PC에서 보내는 직렬신호는 들어오는지..문자는 수신이 됬는지는 확인하셨나요?

하드웨어 설계 및 개발에 대하여 개발자들이 자유롭게 토론하는 공간입니다.
- Q&A, 자유주재 토론, 관련 정보 공유
- 분야 : 마이크로프로세서 응용, 전기/전자(아날로그/디지털) 회로 설계, C/C++ 프로그래밍, 펌웨어,
         PCB Artwork, 트러블슈팅 등 하드웨어 설계에 관한 전반인 내용
※ 게시글에 맞는 분류를 선택하여 글을 작성해 주시면 쾌적한 사이트 운영에 많은 도움이 됩니다.
※ 하드웨어 인사이트는 회원들간의 거래정보를 게재할 뿐이지, 그 어떤 책임과 의무도 가지지 않습니다.

search
번호 분류 제목 글쓴이 조회 수 날짜
2306 자유주제 HOT스마트폰을 쓰는 한 방법9 견우7 16088 2011.10.17
2305 자유주제 HOTMCU를 공부하며 아쉬운 점...3 견우7 18083 2011.10.17
2304 자유주제 HOT직렬화(serializing )란 뭐죠?6 견우7 16350 2011.10.11
2303 자유주제 HOT버그신고 : 내용 유1 견우7 14888 2011.10.05
2302 자유주제 HOT건의합니다.3 Interrupter 14222 2011.09.28
2301 자유주제 HOT스마트그리드 기술로 로봇이 우리집을 관리해준다!4 일렉트로닉 16611 2011.09.27
2300 자유주제 HOT버그신고 : 내용 유1 견우7 15447 2011.09.27
2299 자유주제 HOT로봇청소기에 관련해 문의 드리고 싶어요1 쭈쭈맘 15316 2011.09.25
2298 자유주제 HOT윈도우 7 홈프리미엄에서 쿼터스 ll 설치안되시는 분 있으신가요?1 안녕하세요. 8005 2011.09.17
2297 자유주제 HOT사람이 죽으라는 법은 없나봅니다3 혈청 16797 2011.08.25
2296 자유주제 HOTgx680 노트북 샀어염3 빛나는 영혼 8808 2011.08.12
2295 자유주제 HOT제주도 여행기....2 꼬마최민수 17032 2011.08.10
2294 자유주제 HOT안녕하세요 아둘란 17030 2011.08.08
2293 자유주제 HOT샘플 SMT 가능한 업체를 찾고 있습니다.2 메갈로돈 18314 2011.08.02
2292 자유주제 HOT[버그신고] 내용 有1 우띠 17907 2011.07.28
2291 자유주제 HOT제어 공부를 같이 해볼 수 없을까요??2 류야 13233 2011.07.25
2290 자유주제 HOT호주에서 회로 설계하시는 분 계신가요?1 메갈로돈 21701 2011.07.21
2289 자유주제 HOTDC-DC IC 관련 입니다. 무적쫑 15634 2011.06.22
2288 자유주제 HOT고소왕ㅋ5 데이비스깽 3362 2011.06.18
2287 자유주제 HOT블루투스 모듈에 관해서1 데이비스깽 17279 2011.06.18
Prev 1 ... 15 16 17 18 19 20 21 22 23 24 ... 135 Next
  • 지식이란 자기가 그만큼 배웠다는 교만이고, 지혜는 자기가 더 이상 알지 못한다는 겸손이다.
    - 쿠퍼
  • * 납포인트 정보 *
  • 글 작성 : 3
  • 댓글 작성 : 1
  • 내 글이 추천받음 : 1
저작권법에 위배되는 콘텐츠는 등록 불가하며, 저작물에 대한 권리는 저작자에게 있습니다.
Copyright 2006-2021 © hardwareis.com, All rights reserved.