Homepage von Peter Rachow Startseite - Home
Forschung und Entwicklung: LCD-Anzeige | Mikrocontroller | Software | Sensoren | Gehäuse | Erfahrungsberichte
Geräte: SBTC3 | SBTC4 | Datenmodem zum PC | Simulator für Drucksensor
#include
<stdio.h>
#include
<stdlib.h>
#define
LCD_INST 0x01
#define
LCD_DATA 0x02
#define
PORTD 0x378
#define
PORTB 0x37A
int main(void);
/*
L C D */
void
outp(unsigned char, unsigned int);
void
sbi(int, int);
void
cbi(int, int);
void
set_e(unsigned char);
void
set_rs(unsigned char);
void
lcd_init(void);
unsigned
int power2(unsigned int);
void
lcd_putchar(unsigned int, unsigned int, unsigned char);
void
lcd_write(unsigned char, unsigned char, unsigned int);
/*
Enable-Leitung setzen */
void
set_e(unsigned char status) /* Pin 6 blau */
{
if(!status)
sbi(PORTB, 1);
else
cbi(PORTB, 1);
}
/*
Register-Select-Leitung setzen */
void
set_rs(unsigned char status) /* Pin 4 gelb */
{
if(status)
sbi(PORTB, 2);
else
cbi(PORTB, 2);
}
/******************************************************/
/*
Ein Zeichen (Befehl bzw. Datum) zum Display senden */
/******************************************************/
void
lcd_write(unsigned char lcdmode, unsigned char value, unsigned int
waitcycles)
{
if(lcdmode == LCD_INST)
outp(11, PORTB); //RS=0, E=0
else
outp(15, PORTB); //RS=1, E=0
delay(waitcycles);
set_e(1);
outp(value & 0xF0, PORTD);
set_e(0);
set_e(1);
outp((value & 0x0F) * 0x10, PORTD);
set_e(0);
delay(waitcycles);
}
void
lcd_putchar(unsigned int row, unsigned int col, unsigned char ch)
{
lcd_write(LCD_INST, col + 128 + row * 0x40, 1);
lcd_write(LCD_DATA, ch, 1);
}
void
lcd_cls()
{
lcd_write(LCD_INST, 1, 5);
}
void
lcd_set_display(int dispon, int cursoron, int blink)
{
lcd_write(LCD_INST, 8 + dispon * 4 + cursoron * 2 + blink, 5);
}
void
lcd_set_entrymode(int cursorincrease, int displayshifted)
{
unsigned char x = 4;
if(displayshifted)
x+= 1;
if(cursorincrease)
x+= 2;
lcd_write(LCD_INST, x, 5);
}
void
lcd_init()
{
lcd_write(LCD_INST, 40, 30);
lcd_write(LCD_INST, 40, 30);
lcd_write(LCD_INST, 40, 30);
lcd_write(LCD_INST, 2, 5);
lcd_write(LCD_INST, 8, 5);
lcd_set_display(1, 0, 0);
lcd_cls();
lcd_set_entrymode(0, 0);
}
void
lcd_putstring(unsigned int row, unsigned int col, unsigned char *s)
{
unsigned int t1 = col;
while(*(s))
{
printf("%d\n", t1);
lcd_putchar(row, t1++, *(s++));
}
}
/*************************************************/
/*
DUMMIE-Funcs vom AVR f�r
TC
*/
/*************************************************/
unsigned
int power2(unsigned int ex)
{
unsigned int t1, x = 1;
for(t1 = 1; t1 <= ex; t1++)
x *= 2;
return x;
}
void
sbi(int port, int bit)
{
outport(port, inport(port) | power2(bit));
}
void
cbi(int port, int bit)
{
if(inport(port))
outport(port, inport(port) ^ power2(bit));
}
void
outp(unsigned char value, unsigned int port)
{
outportb(port, value);
}
int
main(void)
{
lcd_init();
while(!kbhit())
{
lcd_putstring(0, 0, "Hallo,");
lcd_putstring(1, 0, "Welt!");
delay(1000);
}
return 0;
}