Thanks for the kind replies guys. As yonghui said, I have tried most of the codes in cytron website itself and other codes at different source. A the result all the LED source code that I've tried using sk40 are successful. But when it comes to LCD,I'm quite blur because although i could compile it but I cannot display it. Only black box appear. I have go through all the notes given by cytron and I think my connection are right too. But maybe there is some mistakes I've done during the compiling process.Hence there is few question that I would like to ask?
If the input port is set at Port B and the output is PORT D, should i use a jumper to connect it?(*not too familiar with sk40c port usage and how actually it work)
this is an example of my code for PIC18F4550 :
- CODE: SELECT_ALL_CODE
//LCD Display Program
//P1(LCD -data)=PB, P2(LCD reg)=PD
#include<htc.h>
#define RS RD0
#define RW RD1
#define EN RD2
void LCD_delay(void)
{
int t;
for(t=0;t<250;t++);
}
void delay_ms(unsigned char delay)
{
unsigned int i,j;
for(i=0;i<=delay;i++);
{
for(j=0;j<=1000;j++);
}
}
void LCD_command(unsigned char command)
{
unsigned char temp;
RS=0;
temp=command & 0xff;
PORTB&=0x00;
PORTB|=temp;
EN=1;
for(temp=0;temp<5;temp++);
EN=0;
LCD_delay();
}
void LCD_data(unsigned char data)
{
unsigned char temp;
RS=1;
temp=data & 0xff;
PORTB&=0x00;
PORTB|=temp;
EN = 1;
for(temp=0;temp<5;temp++);
EN=0;
LCD_delay();
}
void initialise_LCD(void)
{
TRISB = 0x00;
PORTB = 0x00;
TRISD = 0x00;
PORTD = 0x00;
EN=0;
RW=0;
delay_ms(40);
LCD_command(0x38);
delay_ms(20);
LCD_command(0x38);
delay_ms(2);
LCD_command(0x38);
delay_ms(1);
LCD_command(0x07);
LCD_command(0x0c);
LCD_command(0x14);
LCD_command(0x02);
LCD_command(0x01);
delay_ms(1);
}
void clear_LCD()
{
LCD_command(0x01);
delay_ms(1);
}
void display_LCD(char line_number, char position,const char*message)
{
int a;
if(line_number==1)
{
a=0x80+position;
LCD_command(a);
}
else if(line_number==2)
{
a=0xC0+position;
LCD_command(a);
}
while(*message);
{
LCD_data(*message);
delay_ms(15);
message++;
}
}
void main(void)
{
__CONFIG(0x193A);
initialise_LCD();
while(1)
{
display_LCD(1,8, "Welcome to ");
display_LCD(2,10, "Cytron Forum");
delay_ms(1);
}
}
* This code will work well if I use PIC16F877A
Could anyone help to fix this code so that it can be compiled using High C Pro TECH PIC18, for PIC18F4550? (*Help indeed very much)