Advertisement
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 PB0
- //RW PB1
- //E PB2
- //DATA PD
- #define RS 0
- #define RW 1
- #define E 2
- void LCD2x16_init(void)
- {
- PORTB &= ~(1<<RS);
- PORTB &= ~(1<<RW);
- PORTB |= (1<<E);
- PORTD = 0x38; // dwie linie, 5x7 punktow
- PORTB &=~(1<<E);
- _delay_us(120);
- PORTB |= (1<<E);
- PORTD = 0x0e; // wlacz wyswietlacz, kursor, miganie
- PORTB &=~(1<<E);
- _delay_us(120);
- PORTB |= (1<<E);
- PORTD = 0x06;
- PORTB &=~(1<<E);
- _delay_us(120);
- }
- void LCD2x16_clear(void){
- PORTB &= ~(1<<RS);
- PORTB &= ~(1<<RW);
- PORTB |= (1<<E);
- PORTD = 0x01;
- PORTB &=~(1<<E);
- delay_ms(120);
- }
- void LCD2x16_putchar(int data)
- {
- PORTB |= (1<<RS);
- PORTB &= ~(1<<RW);
- PORTB |= (1<<E);
- PORTD = data;
- PORTB &=~(1<<E);
- _delay_us(120);
- }
- void LCD2x16_pos(int wiersz, int kolumna)
- {
- PORTB &= ~(1<<RS);
- PORTB &= ~(1<<RW);
- PORTB |= (1<<E);
- delay_ms(1);
- PORTD = 0x80+(wiersz-1)*0x40+(kolumna-1);
- delay_ms(1);
- PORTB &=~(1<<E);
- _delay_us(120);
- }
- int main(void){
- char linia1[17],linia2[17];
- int pom1,pom2,pom3,pom4;
- //char www[16] = "www-> are.net.pl";
- //char email[16] = "biuro@are.net.pl";
- char tmp[16];
- int i;
- int j=4;
- DDRD = 0xff;
- PORTD = 0x00;
- DDRB = 0xff;
- PORTB = 0x00;
- pom1=123;
- ;pom1=ADC;//0-1023
- pom2=pom1/1000;
- linia1[8]=pom2+'0';
- _delay_ms(200);
- LCD2x16_init();
- LCD2x16_clear();
- for(i=0;i < 17;i++)
- LCD2x16_putchar(linia1[i]);
- LCD2x16_pos(2,1);
- for(i=0;i < 17;i++)
- LCD2x16_putchar(linia2[i]);
- delay_ms(3000);
- LCD2x16_clear();
- for(i=0;i < 17;i++)
- LCD2x16_putchar(linia1[i]);
- while(1)
- {
- LCD2x16_clear();
- LCD2x16_pos(2,1);
- sprintf(tmp,"Dzialam juz %2is ",j);
- j++;
- for(i=0;i < 16;i++)
- LCD2x16_putchar(tmp[i]);
- delay_ms(1000);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement