Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

jbug connecting a lcd to con8

Status
Not open for further replies.

ghostman11

Well-Known Member
can a lcd (16x2 chars HD44780) be connected to con8 of the jbug or would it be better if i took the 18f1320 off the bug and used a breadboard? if i need to use a bread board what other bits do i need to add to it? sorry if i havnt been clear its late and i am cream crackered! lol maybe i should ask in the morn.
sorry to bother you all again with another question :D
 
I made a very crude adapter to connect to con3.

Mike.
 

Attachments

  • LCD.jpg
    LCD.jpg
    60.9 KB · Views: 171
isnt con3 connected to the 18f2550 that does the programing?? if so wouldnt programing it mess up the june bug programing the 18f1320?? or have i got something very wrong again? :D would you mind explaing how your set up works for me please pommie as i would hate to mess the bug up as i am starting to like it in a odd kind of love/hate relationship lol:D:D
 
Sorry, I meant con8. Here are pictures of front and back and the code I used to access it,
Code:
#define LCDPORT LATA 
#define LCDTRIS TRISA
#define LCD_RS LATBbits.LATB4
#define LCD_TRIS_RS TRISBbits.TRISB4
#define LCD_E LATBbits.LATB1
#define LCD_TRIS_E TRISBbits.TRISB1

void Delay(int); 
void WriteCommand(unsigned char);
void WriteChar(unsigned char);
void WriteNibble(unsigned char);
void WaitLCDBusy(void);
void WriteLCD(unsigned char);
void InitLCD(void);
void PutMessage(rom char*);
void PutMessageAt(unsigned char,unsigned char,rom char*);
void PutHex(unsigned char);
void PutNibble(unsigned char);

//Write a string to the LCD
void PutMessage(rom char *Message){
    while(*Message!=0)
        WriteChar(*Message++);
} 

//Set position and write string.
void PutMessageAt(unsigned char X,unsigned char Y,rom char *Message){
    WriteCommand(0x80+(--Y<<6)+--X);
    while(*Message!=0)
        WriteChar(*Message++);
}

void PutHex(unsigned char Num){
    PutNibble(Num>>4);
    PutNibble(Num&0x0f);
}

void PutNibble(unsigned char num){
    if (num>9){
        WriteChar(num+'A'-10);
    }
    else{
        WriteChar(num+'0');
    }
}

//Initialises the LCD
void InitLCD(void){
    LCDTRIS &= 0xE1;                //ensure data bits are output
    LCD_E=0;                        //clear enable
    LCD_RS = 0;                     //going to write command
    LCD_TRIS_E=0;                   //Set enable to output
    LCD_TRIS_RS=0;                  //set RS to output
    Delay(30);                      //delay for LCD to initialise.
    WriteNibble(0x30);              //Required for initialisation
    Delay(5);                       //required delay
    WriteNibble(0x30);              //Required for initialisation
    Delay(1);                       //required delay
    WriteCommand(0x20);             //set to 4 bit interface
    WriteCommand(0x2c);             //set to 4 bit interface, 2 line and 5*10 font
    WriteCommand(0x01);                //clear display
    WriteCommand(0x06);             //move cursor right after write
    WriteCommand(0x0C);             //turn on display
}

//wait for the LCD to finish last command.
void WaitLCDBusy(void){
	Delay(5);
}

//Send a command to the LCD
void WriteCommand(unsigned char command){
    WaitLCDBusy();                  //wait until not busy
    LCD_RS = 0;                     //setup to send command
    WriteNibble(command>>4);        //write the high nibble
    WriteNibble(command);           //then the low nibble
}

//Send a character to the LCD
void WriteChar(unsigned char chr){
    WaitLCDBusy();                  //wait until not busy
    LCD_RS=1;                       //Setup to send character
    WriteNibble(chr>>4);            //write the high nibble
    WriteNibble(chr);               //then the low nibble
}

//Send any 4 bits to the LCD
void WriteNibble(unsigned char command){
    LCDPORT &= 0xE1;                //clear the data bits
    LCDPORT |= ((command<<1) & 0x1E);    //or in the new data
    LCD_E = 1;                      //enable the LCD interface
    LCD_E = 0;                      //disable it
}

// delay mS at 20MHz
void Delay(int Time){
int i,j;
    for(j=0;j<Time;j++)
        for(i=0;i<275;i++);
}

I have no idea why I used a resistor but it's a 330Ω one.

Mike.
 

Attachments

  • back.jpg
    back.jpg
    105.9 KB · Views: 153
  • Front.jpg
    Front.jpg
    86.9 KB · Views: 158
thanks again pommie :D looks like i need to order a few bits and make me one of them :D still gives me a little time to go thru your code :D i need to get my head around c. your code is well edited but i may have a couple of questions (noob ones) later i hope you dont mind. i will see how i get on first, cheers again mate
 
Last edited:
No problem with any questions and if you're unsure of C it would be quite easy to convert to Swordfish Basic. Unfortunately, I'm not going to be around for the next week as I'm off to Vanuatu. So if you don't get an answer it's cause I'm off scuba diving or some other holiday thing.

Mike.
 
enjoy your vacation mate hope its warmer than it is here! thanks 3v0 i may need to take you up on your offer :D
 
It'll definitely be warmer than Devon. Sea temperature is currently 28°C.

Mike.
 
is -3c here today on the edge of dartmoor :O i wont be dipping my toes in the water for a while :D. not that i do much scuba theese days
 
We keep getting the odd news report about how cold it is there. Being from Manchester I know how cold it can get.

Mike.
 
  • Like
Reactions: 3v0
Yes, but warm rain is nice. I used to hate rain but I quite enjoy it now. Anyway, I'll get wet diving so what does it matter.:D

Mike.
 
i tried to compile the code using mikroc compiler. please bear in mind i have been able to do nothing in c so far with this compiler :(, and i got the following errors

Code:
0 1 mikroCPIC1618.exe -MSF -DBG -pP18F1320 -DL -O11111114 -fo4 -N"C:\Documents and Settings\jason\My Documents\newlcd test.mcppi" -SP"C:\Program Files\Mikroelektronika\mikroC PRO for PIC\defs\" -SP"C:\Program Files\Mikroelektronika\mikroC PRO for PIC\uses\P18\" -SP"C:\Documents and Settings\jason\My Documents\" "newlcd test.c" "__Lib_Math.mcl" "__Lib_MathDouble.mcl" "__Lib_System.mcl" "__Lib_Delays.mcl" "__Lib_LcdConsts.mcl" "__Lib_Lcd.mcl"  
0 125 All files Preprocessed in 40 ms  
0 121 Compilation Started newlcd test.c
15 300 Syntax Error: ')' expected,  but 'Chr' found newlcd test.c
16 369 Specifier needed newlcd test.c
16 300 Syntax Error: ')' expected,  but 'char' found newlcd test.c
21 300 Syntax Error: ')' expected,  but 'char' found newlcd test.c
24 369 Specifier needed newlcd test.c
24 394 Invalid declarator expected'(' or identifier newlcd test.c
27 369 Specifier needed newlcd test.c
27 300 Syntax Error: ')' expected,  but 'char' found newlcd test.c
28 312 Internal error '' newlcd test.c
0 102 Finished (with errors): 04 Jan 2010, 15:36:53 newlcd test.mcppi

could you give me some pointers please, at this stage a nudge in the right direction would be nice :D i need to get to grips with mikro c so i am just after a nudge ;) (hopefully)
 
It's difficult to mess up the Junebugs 18F2550
But you can erase & reprogram the 18F1320 tutor thousands of times.

Ghost I'm going to send you a bare Unicorn PCB, this was designed to handle LCDs and can be programmed / debugged with the Junebug.
 
Last edited:
thanks alot bill much appreciated! trust me i have erased and reprogramed the bug MANY times so far lol :D. its a great bit of kit i am still a little cautious with it as i tend to be a little heavy handed and the last thing i want to do is kill it lol. is probally one the best purchases i made last year and trust me i made a few ;) :d btw happy new year everyone
 
ok i am having a complete mare with mikroc pro, and before it is sugested i have asked over at there forums but tbh i dont find them much help.
i must be making a fundemental noob cockup, every time i try and compile code that i have taken from a post or an example i get loads of errors the most common being undeclared identifier.......i have read the help file and all it says under errors is that there is indeed a undeclared identifier error! wtf use is that?? it dosent explain what it is or how to correct it.
anyway my thinking is i must be leaving out some sort of file when i first build a project??? can any one explain very simply (hopefuly with a short example) how you actualy write and compile code in mikro c. i have downloaded the usermanual but it dosnt help me at the moment, i feel if i could get over this first basic hurdle i might stand a chance of cracking c :D, i would use another compiler but to be honest i paid soo much for this one i am reluctant to just discard it. cheers in advance and sorry if it seems like i am just having a moan
 
as an example i took the following code from there web site
Code:
void main() {
 PORTB = 0 ;
 TRISB = 0 ;
 while (1) ;
 PORTB = ~PORTB ;
 Delayms (1000) ;
}

and i get 6 324 Undeclared identifier 'Delayms' in expression C

so what basic noob mistake am i making :D
 
as an example i took the following code from there web site
Code:
void main() {
 PORTB = 0 ;
 TRISB = 0 ;
 while (1) ;
 PORTB = ~PORTB ;
 Delayms (1000) ;
}

and i get 6 324 Undeclared identifier 'Delayms' in expression C

so what basic noob mistake am i making :D

The Delayms(1000); should be Delay_ms(1000);
It's a small synatax error.

If it's undeclared then it's most likely that you used the wrong synatax and that the compiler does'nt understand like the above. :D

Different compilers use differnt synataxes, so a little edit is requiered to port code.
 
thanks 17! i was about to post i had sorted it lol thanks for the info! what realy annoys me is i took the code from mikroelectronica's code example of a first program direct from there own pdf. how the hell is a noob ment to learn when the company that makes the compiler has basic errors in there newbie examples!!! i have been so unimpressed with the software so far and lack of support they seem to give. i wouldnt mind but i dont consider mikroc pro cheap. still on the plus side i have gained a little more knowledge and i guess thats what its all about:D
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top