BASIC4MCU | 질문게시판 | ATmega128 FND LED 부저 3초동안 구동
페이지 정보
작성자 master 작성일2018-12-03 09:15 조회7,254회 댓글0건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=6188
본문
ATMEGA과제 관련해서 질문있습니다.1. LED가 3초 동안 켜져야합니다.2. FND가 "1234" 디스플레이 돼야합니다.3. Buzzer가 3초 동안 소리나야합니다.4. 1,2,3번이 한 거 번에 나타나야합니다.위가 바로 저희 과제의 조건입니다. 아래는 저희가 짠 코드인데, Putty에 Select가 뜨지 않고 바로 숫자만 나옵니다. 그리고 출력을 했을때 상대의 아트메가에 뜨지 않고 제 아트메가에 출력이 됩니다. 어디를 수정을 해야 오류를 잡을 수 있을까요? 내공 100 드릴게요 ㅠㅠ옥현이형 도와주세요!!!!!!#include <avr/io.h> // AVR 기본 include#define NULL 0#define F_CPU 16000000UL#include <util/delay.h>unsigned char digit[4] = {0x06,0x5b,0x4f,0x66};unsigned char fnd_sel[4] = {0x08,0x04,0x02,0x01};void putchar0(char c) // 1 char를 송신(Transmit)하는 함수{while(!(UCSR0A & 0x20)); // UCSR0A 5번 비트 = UDREUDR0 = c; // 1 character 전송}char getchar0() // 1 character를 수신(receive)하는 함수{while (!(UCSR0A & 0x80));// UCSR0A 7번 비트 = RXC(Receiver Complete)return(UDR0); // 1 character 수신}void puts0(char *ptr) // string을 송신하는 함수{while(1){if (*ptr != NULL) // 1글자씩 송신putchar0(*ptr++);else return; // string 끝이면 종료}}void putchar1(char c) // 1 char를 송신(Transmit)하는 함수{while(!(UCSR1A & 0x20)); // UCSR0A 5번 비트 = UDREUDR1 = c; // 1 character 전송}char getchar1() // 1 character를 수신(receive)하는 함수{while (!(UCSR1A & 0x80));// UCSR0A 7번 비트 = RXC(Receiver Complete)return(UDR1); // 1 character 수신}void puts1(char *ptr) // string을 송신하는 함수{while(1){if (*ptr != NULL) // 1글자씩 송신putchar1(*ptr++);else return; // string 끝이면 종료}}void init_uart(){UBRR0H = 0; // 12비트가 의미를 가짐,UBRR0L = 8; // ATmega128 datasheet 참조 요망// 16Mhz, 115200 baud의 경우UCSR0B = 0x18; // Receive(RX) 및 Transmit(TX) EnableUCSR0C = 0x06; // UART Mode, 8 Bit Data, No Parity, 1 Stop BitUBRR1H = 0; // 12비트가 의미를 가짐,UBRR1L = 8; // ATmega128 datasheet 참조 요망// 16Mhz, 115200 baud의 경우UCSR1B = 0x18; // Receive(RX) 및 Transmit(TX) EnableUCSR1C = 0x06; // UART Mode, 8 Bit Data, No Parity, 1 Stop Bit}int main(){char prompt[]="Youngju Lee>> "; // 본인이름 입력할것.char *ptr;char c;init_uart();while (1){if((UCSR0A & 0x80)){c = getchar0( ); // 1 character를 받아서switch (c){ case '1' :putchar0(c);DDRA = 0xff;PORTA = 0xff;_delay_ms(3000);PORTA = 0x00;break;case '2' :DDRC = 0xff;DDRG = 0x0f;putchar0(c);for(int j=0;j<150;j++){for(int i=0;i<4;i++){ PORTC = digit[i];PORTG = fnd_sel[i];_delay_ms(5); }}PORTC = 0x00;PORTG = 0x00;break;case '3' :putchar0(c);for(int i=0;i<1499;i++){PORTB = 0x10;_delay_ms(1);PORTB = 0x00;_delay_ms(1);}break;case '4' :putchar0(c);DDRA = 0xff;DDRC = 0xff;DDRG = 0x0f;DDRB = 0x10;for(int z=0;z<375;z++){for(int i=0;i<4;i++){PORTA = 0xff;PORTC = digit[i];PORTG = fnd_sel[i];PORTB = 0x10;_delay_ms(1);PORTB = 0x00;_delay_ms(1);}}PORTA = 0x00;PORTC = 0x00;PORTG = 0x00;PORTB = 0x00;break;}}if((UCSR1A & 0x80)){c = getchar1( ); // 1 character를 받아서putchar0(c); // 원래 character를 돌려보냄}if (c == '\r') // CR(Carrage Return)이면{putchar1('\n'); // NL(New Line)을 하나 더// 보내서 줄바꿈을 한 뒤ptr = prompt; // prompt(“JKIT-128-1> “)를 다시puts1(ptr); // 내보냄}}}
//
// MCU BASIC: https://www.basic4mcu.com// DateTime : 2018-12-03 오전 9:19:37// by Ok-Hyun Park//#define F_CPU 16000000UL#include <avr/io.h>#include <util/delay.h>//#define NULL 0//unsigned char digit[4] ={0x06,0x5b,0x4f,0x66};unsigned char fnd_sel[4]={0x08,0x04,0x02,0x01};//char RxCharMy() { while(!(UCSR0A&0x80)); return(UDR0); }char RxCharAVR(){ while(!(UCSR1A&0x80)); return(UDR1); }void TxCharMy(char c) { while(!(UCSR0A&0x20)); UDR0=c; }void TxCharAVR(char c){ while(!(UCSR1A&0x20)); UDR1=c; }void TxStrMy(char*s) { while(*s)TxCharMy(*s++); }void TxStrAVR(char*s){ while(*s)TxCharAVR(*s++); }//int main(){int i,j;char c,prompt[]="Youngju Lee>>"; // 본인이름 입력할것.DDRA=0xff; DDRC=0xff; DDRG=0x0f; DDRB=0x10;UBRR0L=8; UCSR0B=0x18; // 퓨티UBRR1L=8; UCSR1B=0x18; // 다른 AVR_delay_ms(2000);TxStrMy(prompt);while(1){if(UCSR1A&0x80){c=RxCharAVR(); // 다른 AVR로 부터 1 character를 받아서switch(c){case '1':{ TxCharMy(c); PORTA=0xff; _delay_ms(3000); PORTA=PORTC=PORTG=PORTB=0; break; }case '2':{ TxCharMy(c);for(j=0;j<750;j++){for(i=0;i<4;i++){ PORTC=digit[i]; PORTG=fnd_sel[i]; _delay_ms(1); }}PORTA=PORTC=PORTG=PORTB=0;break;}case '3':{ TxCharMy(c);for(i=0;i<3000;i++){ PORTB^=0x10; _delay_ms(1); } PORTA=PORTC=PORTG=PORTB=0;break;}case '4':{ TxCharMy(c);PORTA=0xff;for(j=0;j<750;j++){for(i=0;i<4;i++){ PORTC=digit[i]; PORTG=fnd_sel[i]; PORTB^=0x10; _delay_ms(1); }}PORTA=PORTC=PORTG=PORTB=0;break;}}}//if((UCSR0A&0x80)){ // 퓨티로 부터 1 character를 받아서c=RxCharMy(); TxCharAVR(c);if(c=='\r'){ TxCharAVR('\n'); TxStrAVR(prompt); }}}}
댓글 0
조회수 7,254등록된 댓글이 없습니다.