You are on page 1of 6

//-----------------------------------------------------------------------------

// Includes

//-----------------------------------------------------------------------------

#include <SI_C8051F340_Register_Enums.h> // SFR declarations

SI_SBIT(RS, SFR_P1, 0);

SI_SBIT(RW, SFR_P1, 1);

SI_SBIT(EN, SFR_P1, 2);

void OSCILLATOR_Init(void);

void PORT_Init(void);

void lcd_init(void);

void lcd_cmd(unsigned char);

void lcd_dat(unsigned char);

void lcd_dis(unsigned int, const unsigned char);

void enable(void);

void delayms(unsigned int);

const unsigned char* Line1 = " Logsun Systems\0";

const unsigned char* Line2 = " 16x2 LCD\0";

//-----------------------------------------------------------------------------

// SiLabs_Startup() Routine

// ----------------------------------------------------------------------------

// This function is called immediately after reset, before the initialization

// code is run in SILABS_STARTUP.A51 (which runs before main() ). This is a

// useful place to disable the watchdog timer, which is enable by default

// and may trigger before main() in some instances.


//-----------------------------------------------------------------------------

void SiLabs_Startup (void)

// Disable the watchdog here

PCA0MD &= ~0x40; //Disable Watchdog timer.

//-----------------------------------------------------------------------------

// main() Routine

// ----------------------------------------------------------------------------

// Note: the software watchdog timer is not disabled by default in this

// example, so a long-running program will reset periodically unless

// the timer is disabled or your program periodically writes to it.

//

// Review the "Watchdog Timer" section under the part family's datasheet

// for details. To find the datasheet, select your part in the

// Simplicity Launcher and click on "Data Sheet".

//-----------------------------------------------------------------------------

int main (void)

int l =0;

PORT_Init();

OSCILLATOR_Init();

lcd_init();

//(1,"A");

// lcd_dis(2,"*");

while(Line1[l]!='\0')
{

lcd_dat(Line1[l]);

l++;

delayms(50);

l=0;

lcd_cmd(0xC0);

delayms(10);

while(Line2[l]!='\0')

lcd_dat(Line2[l]);

l++;

delayms(50);

// lcd_dis(1,Line1);

//lcd_dis(2,Line2);

while (1) {} // Spin forever

void OSCILLATOR_Init(void){

OSCICN |= 0x03;

}
void PORT_Init(void){

P0MDIN |= 0xFF;

P1MDIN |= 0x07;

P0MDOUT = 0xFF;

P1MDOUT = 0x07;

XBR1 = 0x40;

void delayms(unsigned int time)

int s,t;

for(s=0;s<time;s++){

for(t=0;t<45;t++);

void enable(void){

EN = 1;

delayms(5);

EN = 0;

void lcd_cmd(unsigned char cmd){


P0 = cmd;

RW = 0;

RS = 0;

enable();

void lcd_dat(unsigned char datA)

P0 = datA;

RW =0;

RS =1;

enable();

void lcd_init()

lcd_cmd(0x38); //2 lines 5x7 matrix

delayms(10);

lcd_cmd(0x0F); // LCD ON, Cursor Blink

delayms(10);

lcd_cmd(0x01); // Clear Screen

delayms(10);

lcd_cmd(0x01);

delayms(10);

lcd_cmd(0x80); // Force Cursur to begining of 1st line

void lcd_dis(unsigned int row, const unsigned char* string)

{
unsigned int ptr = 0;

if(row==1){

lcd_cmd(0x80);

else

lcd_cmd(0xC0);

while(string[ptr]!= '\0')

lcd_dat(string[ptr]);

ptr++;

delayms(50);

You might also like