티스토리 뷰

예제 2


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <mega128.h>
 
void putch_USART1(char data)
{
             while(!(UCSR1A & (1<<UDRE1)));
             UDR1 = data;
}
char getch_USART1(void)
{
             while(! (UCSR1A & (1<<RXC1)));
             return UDR1;
}
void Init_USART1(void)
{
             UCSR1A = 0x00;
             UCSR1B = (1<<RXEN1) | (1<<TXEN1);
             UCSR1C = (1<<UCSZ11) | (1<<UCSZ10);
             
             UBRR1H = 0x00;
             UBRR1L = 0x07;
}                          
 
void main(void)
{
             Init_USART1();
             while(1)
             {
                          putch_USART1(getch_USART1());
             }
}
cs



예제 3


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <mega128.h>
 
#define MAXLEN 16
 
unsigned char str[MAXLEN];
unsigned char ch;
unsigned char *ptr;
 
interrupt [USART1_DRE] void usart1_transmit(void)
{
             while(!(UCSR1A & (1<<RXC1)));
             UDR1 = *str;
             
}            
 
interrupt [USART1_RXC] void usart1_receive(void)
{
             while(!(UCSR1A & (1<<UDRE1)));
             str[ch] = UDR1;
             
}    
 
void Init_USART1(void)
{
             UCSR1A = 0x00;
             UCSR1B = (1<<TXCIE1)|(1<<RXCIE1)|(1<<UDRIE1)|(1<<RXEN1)|(1<<TXEN1);
             
             UCSR1C = (1<<UCSZ11)|(1<<UCSZ10);
             UCSR1C &= ~(1<<UMSEL0);
             
             UBRR1H = 0x00;
             UBRR1L = 0x07;
             
             SREG = 0x80;
}
 
void main(void)
{
             Init_USART1();
}
 
cs



예제 4

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <mega128.h>
 
void putch_USART1(char data)
{
             while(!(UCSR1A & (1<<UDRE1)));
             UDR1 = data;
}
char getch_USART1(void)
{
             while(!(UCSR1A &(1<<RXC1)));
             return UDR1;
}
void Init_USART1(void)
{
             UCSR1A = 0x02;
             UCSR1B = (1<<RXEN1) | (1<<TXEN1);
             UCSR1C = 0x0c;
             
             UBRR1H = 0x00;
             UBRR1L = 15;
}
 
void main(void)
{
             DDRB = 0xFF;
             Init_USART1();
             while(1)
             {
                          putch_USART1(getch_USART1());
                          if(UDR1 == '1')
                          {
                                       PORTB = 0x00;
                          }                         
                          else if(UDR1 == '2')
                          {
                                       PORTB = 0xff;
                          }
             }
}
cs



문제 1


다음과 같이 하이퍼 터미널에 출력하시오

- 폴링방식

- PC에서 입력한 문자를 대문자 소문자로 서로 변환하여 출력

- 알파벳이 아니면 ? 출력

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <mega128.h>
 
unsigned char buffer;
 
 
void putch_USART1(char data)
{
             while(!(UCSR1A & (1<<UDRE1)));
             UDR1 = data;     
             
             if(buffer >= 65 && buffer <= 90){
                          buffer += 32;
             
             }else if(buffer >= 97 && buffer <= 122){
                          buffer -= 32;
             }                         
             else {
                          buffer = 63;
             }   
             
             UDR1 = buffer;
}
char getch_USART1(void)
{
             while(! (UCSR1A & (1<<RXC1)));
             
             buffer = UDR1;
                 
             
             
             
             return buffer;
             
             
             
}
void Init_USART1(void)
{
             UCSR1A = 0x00;
             UCSR1B = (1<<RXEN1) | (1<<TXEN1);
             UCSR1C = (1<<UCSZ11) | (1<<UCSZ10);
             
             UBRR1H = 0x00;
             UBRR1L = 95;
}                          
 
void main(void)
{
 
             buffer = '\n';
 
             Init_USART1();
             while(1)
             {                        
                          putch_USART1(getch_USART1());
             }
}
 
cs




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <mega128.h>
#include <io.h>
#include <delay.h>
 
unsigned char buffer;
int location;
int line;
 
void lcd_func(void){
    PORTG = 0x01;       // 명령어 쓰는 신호
    PORTA = 0x38;       // 0b00111000    8비트, 2행, 5*7도
    delay_us(39);
    PORTG = 0x00;
}
void lcd_pic(void){
    PORTG = 0x01;      
    PORTA = 0x0e;       // 0b00001110   화면on, 커서 on, 블링크 off
    delay_us(39);
    PORTG = 0x00;
}
void lcd_mv(void){
    PORTG = 0x01;
    PORTA = 0x06;       // 0b00000110   중가, 표시시프트 off
    delay_us(39);
    PORTG = 0x00;
}
void lcd_clear(void){
    PORTG = 0x01;
    PORTA = 0x01;       // clear
    delay_us(2);
    PORTG = 0x00;
}
void lcd_data(unsigned char a, unsigned char b){
    unsigned char sw;
    sw = 0x00;
    if(a == 1)sw = 0xc0;    // a가 1일 때, sw는 0b11000000; 0b00000000;
    
    PORTG = 0x01;           // 명령어 신호
    PORTA = (0x80|b|sw);    // 0b10000000|8bit|11000000 or 00000000 == 0b11010000|b 하위 7비트 사용해서 DDRAM 저장  
    delay_us(39);
    PORTG = 0x00;
}
void lcd_read(unsigned char a){
    PORTG = 0x05;           // 0b00000101, 쓰기신호, Enable
    PORTA = a;              // 
    delay_us(43);
    PORTG = 0x04;           // 100 쓰기, Disenable
}
 
 
 
void putch_USART1(char data)
{
             while(!(UCSR1A & (1<<UDRE1)));
             UDR1 = data;
             if(location >= 16){
                          location = 0;
                          if(line == 0){
                                       line = 1;
                          }                     
                          else {
                                       lcd_clear();
                                       line = 0;       
                          }
             }
             lcd_data(line,location++);
             lcd_read(data);      
             
             if(buffer >= 65 && buffer <= 90){
                          buffer += 32;
             
             }else if(buffer >= 97 && buffer <= 122){
                          buffer -= 32;
             }                         
             else {
                          buffer = 63;
             }   
             
             UDR1 = buffer;
             lcd_data(line,location++);
             lcd_read(buffer);
}
char getch_USART1(void)
{
             while(! (UCSR1A & (1<<RXC1)));
             
             buffer = UDR1;
                 
             
             
             
             return buffer;
             
             
             
}
void Init_USART1(void)
{
             UCSR1A = 0x00;
             UCSR1B = (1<<RXEN1) | (1<<TXEN1);
             UCSR1C = (1<<UCSZ11) | (1<<UCSZ10);
             
             UBRR1H = 0x00;
             UBRR1L = 0x5f;
}                          
 
void main(void)
{
             DDRG = 0x07;
             DDRA = 0xff;
    
             lcd_clear();
             delay_ms(10);
    
             lcd_func();
             lcd_pic();
             lcd_mv();
 
 
             buffer = '\n';
             location = 0;
             line = 0;
 
             Init_USART1();
             while(1)
             {                        
                          putch_USART1(getch_USART1());
             }
}
 
cs


'프로그래밍 > CodeVision' 카테고리의 다른 글

마이크로프로세서181009  (0) 2018.10.09
181002 마이크로프로세서  (0) 2018.10.02
180904 마이크로프로세서  (0) 2018.09.04
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함