Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Thread Closed: Question answered in tutorial/FAQs

???
10/04/03 15:12
Read: times


 
#56090 - display writing goed wrong
when using the following code for writing to a display the first character is complete black. The data isn't shifted just gone black.

when using the puts getchar combination for writing one line (just to test) i don't see the black character

here is the code

#include <at89x51.h>
#include <stdio.h>
#include "functions.h"

#define lcd_characters 16
#define clearlcd 0x01
#define set_4_bit 0x28


bit up_ff;
bit down_ff;
bit set_ff;
bit enter_ff;

extern bit ledblink;
extern bit flag10ms;
extern bit flag25ms;
extern bit flag100ms;
extern bit flag250ms;
extern bit flag500ms;
extern bit flag1000ms;

bit enter;
bit set;
bit up;
bit down;

char lcd_line1[lcd_characters];
char lcd_line2[lcd_characters];


unsigned int timebase = 0;
extern unsigned int tijd;


/* Init function---------------------------------------------------------------*/

void init (void)
{

/* Output ports init-----------------------------------------------------------*/

P0 = 0;
P2 = 0;
P3 = 0;

/* put all variables in their init state-------------------------------------- */

enter = 0;
set = 0;
up = 0;
down = 0;
ledblink = 0;


/* call the lcd init routine---------------------------------------------------*/

lcdinit();

/* Timer0 and Timer 1 init-----------------------------------------------------*/


TMOD = (TMOD & 0xFF) | 0x20; /* Set T/C0 Mode */

/* Timer 0 settings this uses interrupt 1*/
/* The timer is set to 1 ms interval*/
TL0 = 0x1F; /* Low timer registers*/
TH0 = 0xF0; /* High timer registers*/
ET0 = 1; /* RK: Enable Timer 0 Interrupts */
TR0 = 1; /* RK: Start Timer 0 Running */
EA = 1; /* Global Interrupt Enable */

/* Timer 1 settings this uses interrupt 3*/

//TH1 = 0x1F
//TL1 = 0xF0; reload timer1*/
//ET1 = 1; RK: Enable Timer 1 Interrupts */
//TR1 = 1; RK: Start Timer 1 Running */
//EA = 1; Global Interrupt Enable */

}


/* blinking led----------------------------------------------------------------*/

void alive (void)
{
if (ledblink == 0)
{
led = 1;
ledblink = 1;
}
else
{
led = 0;
ledblink = 0;
}
}


/*Timer function---------------------------------------------------------------*/

/*void timer1_ISR (void) interrupt 3
{
}*/


void timer10_ISR(void) interrupt 1
{

if (timebase < 999)
timebase++;
else
timebase = 0;

if ( !(timebase % 10) )
flag10ms = 1;

if ( !(timebase % 25) )
flag25ms = 1;

if ( !(timebase % 100) )
flag100ms = 1;

if ( !(timebase % 250) )
flag250ms = 1;

if ( !(timebase % 500) )
flag500ms = 1;

if ( !(timebase) )
flag1000ms = 1;

TL0 = 0x1F; /* Low timer registers*/
TH0 = 0xF0; /* High timer registers*/
}


/* lcd controller functions --------------------------------------------------------------*/


void lcdusdelay(int delay)
{
int i;
for(i=0; i<delay; i++);
}


void lcdmsdelay(int delay)
{
int d;
for( d=0; d < delay; d++ )
delay1ms();
}


void delay1ms(void) /* 1ms delay met een 12Mhz kristal. */
{
int i;
for(i=0; i<200; i++);
}


void lcdinit( void )
{ lcdmsdelay(15); /* wait for 15 ms after power on */

lcdwrite(0x03); /* function set command */
lcdmsdelay(5); /* wait for 5 ms */

lcdwrite(0x03); /* function set command */
lcdmsdelay(1); /* wait for 1 ms */

lcdwrite(0x03); /* function set command */
lcdmsdelay(5); /* wait for 5 ms */

lcdwrite(0x02); /* function set (4bit interface) */
lcdmsdelay(1);

lcdwrite(0x02); /* function set 4bit 1/16 duty font = 5x8 */
lcdwrite(0x08);
lcdmsdelay(1);

lcdwrite(0x00); /* display off cursor off blink off */
lcdwrite(0x08);
lcdmsdelay(1);

lcdwrite(0x00); /* display on cursor on blink on */
lcdwrite(0x0F);
lcdmsdelay(1);

lcdwrite(0x00); /* clear display and send cursor to address 0*/
lcdwrite(0x01);
lcdmsdelay(1);

}

/* function for init writing */
void lcdwrite(unsigned char lcd_data)
{
e = 1;
lcdusdelay(40);
P3 = lcd_data;
lcdusdelay(40);
e = 0;
}

/* funcion for sending a string to the display */
/*char putchar(unsigned char c)
{
unsigned char High, Low;

if(c == 'n') return c;

High = (c >> 4) | 0xF0;
Low = (c & 0x0F) | 0xF0;

rs = 1;

P3 &= High; // Write High Nibble
e = 1;
e = 0;
P3 |= 0x0F;

P3 &= Low; // Write Low Nibble
e = 1;
e = 0;
P3 |= 0x0F;

rs = 0;

return c;
}
*/

void printchar(unsigned char c)
{
unsigned char High, Low;

High = (c >> 4) | 0xF0;
Low = (c & 0x0F) | 0xF0;

rs = 1;

P3 &= High; // Write High Nibble
e = 1;
e = 0;
P3 |= 0x0F;

P3 &= Low; // Write Low Nibble
e = 1;
e = 0;
P3 |= 0x0F;

rs = 0;


}


/* function for writing the complete display*/
void lcd_writestring (char *string1, char *string2)
{
int i = 0;
int j = 0;

lcdwrite(0x00); /* display off cursor off blink off */
lcdwrite(0x08);
lcdmsdelay(1);

lcdwrite(0x00); /* clear display and send cursor to address 0*/
lcdwrite(0x01);
lcdmsdelay(1);


for (i=0; i!=16; ++i)
{
printchar(string1[i]);
}

lcdwrite(0x0c);
lcdwrite(0x00);
lcdmsdelay(1);

for (j=0; j!=16; ++j)
{
printchar(string2[j]);
}

lcdwrite(0x00); /* display on cursor off blink off */
lcdwrite(0x0c);
lcdmsdelay(1);

}


/* IO functions-----------------------------------------------------------*/
void check_switches(void)
{



if (up_io == 0 & up_ff == 1)
up = 1;

if (down_io == 0 & down_ff == 1)
down = 1;

if (set_io == 0 & set_ff == 1)
set = 1;

if (enter_io == 0 & enter_ff == 1)
enter = 1;



up_ff = up_io;
down_ff = down_io;
set_ff = set_io;
enter_ff = enter_io;
}


void update_menu(void)
{
if (up == 1)
{
up = 0;
lcd_writestring("Ma 20:17 ", "up down ent set");

}
if (down == 1)
{
down = 0;
lcd_writestring("down is pressed ", "up down set ent");
}


}


/* rtc functions----------------------------------------------------------*/

/*void get_time(void)
{
}
void set_time(void)
{
}
*/


List of 5 messages in thread
TopicAuthorDate
display writing goed wrong            01/01/70 00:00      
   RE: display writing goed wrong            01/01/70 00:00      
      RE: display writing goed wrong            01/01/70 00:00      
         RE: display writing goed wrong            01/01/70 00:00      
            RE: display writing goed wrong            01/01/70 00:00      

Back to Subject List