Rev Author Line No. Line
1089 mija 1 /* mija 2008
2  
3 nanotern01A
4 ver.: 0.0 tested
5 */
6  
7 //*************************************************************
8  
9 #include <avr/io.h>
10 #include <util/delay.h>
11 #include <avr/interrupt.h>
12 #include <avr/sleep.h>
13 #include "rs232.h"
14 #include "lcd.h"
15  
16  
17 //*************************************************************
18  
19 void line_feed(void);
20 void PWM_init(void);
21 void COMP_init(void);
22 ISR(ANA_COMP_vect);
23 void main(void);
24  
25 //*************************************************************
26  
27 #define text "Test 0.0"
28  
29 //*************************************************************
30  
31 uint8_t a,pos;
32 uint8_t buf[8] = text;
33  
34 //*************************************************************
35  
36 void line_feed(void)
37 {
38 uint8_t length;
39 LCD_clear();
40 length=pos;
41 while(pos) {LCD_putc(buf[length-(pos)]);buf[length-(pos--)]=0x20;}
42 LCD_gotoxy(length+1,2);
43 pos=length;
44 }
45  
46 void PWM_init(void)
47 {
48 TCNT1 = 0;
49 OCR1B = 0x1;
50 DDRB |= _BV(PB4);
51 TCCR1A |= _BV(COM1B1) | _BV(WGM10);
52 TCCR1B |= _BV(WGM12) | _BV(CS10);
53 }
54  
55 void PWM_set(void)
56 {
57 if (ACSR & _BV(ACO)) OCR1BL = 0x1f;
58 else OCR1BL = 0x1;
59 }
60  
61 void COMP_init(void)
62 {
63 ACSR |= _BV(ACBG) | _BV(ACIE);
64 DIDR |= _BV(AIN1D);
65 }
66  
67 ISR(ANA_COMP_vect)
68 {
69 PWM_set();
70 }
71  
72 void main(void)
73 {
74 LCD_init();
75 rs232_init();
76 PWM_init();
77 COMP_init();
78 PWM_set();
79  
80 LCD_clear();
81 for (pos=0;pos<8;pos++) LCD_putc(buf[pos]);
82 LCD_gotoxy(1,2);
83  
84 sei();
85  
86 pos=0;
87 for(;;)
88 {
89 a=rs232_get();
90 switch (a)
91 {
92 case ('\n'): line_feed();break;
93 case ('\r'): LCD_gotoxy(1,2);pos=0;break;
94 case ('\f'): LCD_clear();LCD_gotoxy(1,2);pos=0;break;
95 default :if(pos > 7 ) {line_feed();LCD_gotoxy(1,2);pos=0;} LCD_putc(a);buf[pos++]=a;
96 }
97 }
98 }