Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**************************************/
- /* ARE 2008 */
- /* e-mail: biuro@are.net.pl */
- /* www : are.net.pl */
- /**************************************/
- #define F_CPU 8000000UL // 1 MHz
- //#define F_CPU 14.7456E6
- #include <avr/io.h>
- #include <stdio.h>
- #include <util/delay.h>
- #include <string.h>
- void delay_ms(int ms)
- {
- volatile long unsigned int i;
- for(i=0;i<ms;i++)
- _delay_ms(1);
- }
- void delay_us(int us)
- {
- volatile long unsigned int i;
- for(i=0;i<us;i++)
- _delay_us(1);
- }
- //RS PA0
- //RW PA1
- //E PA2
- //DATA PD
- #define RS 0
- #define RW 1
- #define E 2
- void LCD2x16_init(void)
- {
- PORTC &= ~(1<<RS);
- PORTC &= ~(1<<RW);
- PORTC |= (1<<E);
- PORTD = 0x38; // dwie linie, 5x7 punktow
- PORTC &=~(1<<E);
- _delay_us(120);
- PORTC |= (1<<E);
- PORTD = 0x0e; // wlacz wyswietlacz, kursor, miganie
- PORTC &=~(1<<E);
- _delay_us(120);
- PORTC |= (1<<E);
- PORTD = 0x06;
- PORTC &=~(1<<E);
- _delay_us(120);
- }
- void LCD2x16_clear(void){
- PORTC &= ~(1<<RS);
- PORTC &= ~(1<<RW);
- PORTC |= (1<<E);
- PORTD = 0x01;
- PORTC &=~(1<<E);
- delay_ms(120);
- }
- void LCD2x16_putchar(int data)
- {
- PORTC |= (1<<RS);
- PORTC &= ~(1<<RW);
- PORTC |= (1<<E);
- PORTD = data;
- PORTC &=~(1<<E);
- _delay_us(120);
- }
- void LCD2x16_pos(int wiersz, int kolumna)
- {
- PORTC &= ~(1<<RS);
- PORTC &= ~(1<<RW);
- PORTC |= (1<<E);
- delay_ms(1);
- PORTD = 0x80+(wiersz-1)*0x40+(kolumna-1);
- delay_ms(1);
- PORTC &=~(1<<E);
- _delay_us(120);
- }
- int main(void){
- char www[16] = "www-> are.net.pl";
- char email[16] = "biuro@are.net.pl";
- char tmp[17];
- char tmp1[17];
- int sp=60;
- int h= 8;
- int pv=51;
- int e=0;
- int i;
- int j=4;
- DDRD = 0xff;
- PORTD = 0x00;
- DDRC = 0xff;
- PORTC = 0x00;
- DDRB = 0xff;
- PORTB = 0xff;
- ADMUX=0x40;
- _delay_ms(200);
- LCD2x16_init();
- LCD2x16_clear();
- delay_ms(20);
- /* for(i=0;i < 16;i++)
- LCD2x16_putchar(www[i]);
- LCD2x16_pos(2,1);
- for(i=0;i < 16;i++)
- LCD2x16_putchar(email[i]);
- delay_ms(3000);
- LCD2x16_clear();
- for(i=0;i < 16;i++)
- LCD2x16_putchar(www[i]);*/
- while(1)
- {
- if(~PINB & 0x01)
- sp=50;
- if(~PINB & 0x02)
- sp=40;
- if(~PINB & 0x04)
- h=4;
- if(~PINB & 0x08)
- h=10;
- //LCD2x16_clear();
- e=sp-pv;
- sprintf(tmp1,"SP=%2dp PV=%2dC", sp, pv);
- LCD2x16_pos(2,1);
- sprintf(tmp,"H=%2dp E=%3dC",h, e);
- for(i=0;i < 16;i++)
- LCD2x16_putchar(tmp[i]);
- LCD2x16_pos(1,1);
- for(i=0;i < 16;i++)
- LCD2x16_putchar(tmp1[i]);
- delay_ms(100);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment