View previous topic :: View next topic |
Author |
Message |
pic.programmer
Joined: 30 Apr 2015 Posts: 29 Location: Banned - spammer
|
LCD 4 bit and 8 bit codes |
Posted: Sun May 03, 2015 12:26 pm |
|
|
Hi
I made LCD 4 bit and 8 bit code. The functions are similar to mikroElektronika's LCD Library functions. I have tested the code in Proteus and also on mikroElektronika's EasyPIC v7 development board and they work fine. For Proteus I have used Proteus 8.2 SP2. I have used PIC18F46K22 with 8 MHz Crystal.
I don't know how to attach files here. So, I am providing mediafire download link.
http://www.mediafire.com/download/828k71749buv8zj/PIC18F46K22_LCD.rar |
|
![](templates/subSilver/images/spacer.gif) |
dyeatman
Joined: 06 Sep 2003 Posts: 1924 Location: Norman, OK
|
|
Posted: Sun May 03, 2015 12:46 pm |
|
|
Is there a question?
If you are posting these for other people they need to go in the Code Library not here... _________________ Google and Forum Search are some of your best tools!!!! |
|
![](templates/subSilver/images/spacer.gif) |
pic.programmer
Joined: 30 Apr 2015 Posts: 29 Location: Banned - spammer
|
|
Posted: Sun May 03, 2015 12:53 pm |
|
|
Sorry, I am new to this forum. I didn't know. Mods, please move this to the right topic.
One more thing. I have used CCS C 5.044 version Compiler. |
|
![](templates/subSilver/images/spacer.gif) |
pic.programmer
Joined: 30 Apr 2015 Posts: 29 Location: Banned - spammer
|
|
Posted: Sun May 03, 2015 5:08 pm |
|
|
In the LCD_Chr() function, one can replace the switch { ... } statement with below code and make the code work for HD44780 and compatible 16x4 LCD.
Code: | switch(row){
case 1:
LCD_Cmd(0x80 + (column - 1));
break;
case 2:
LCD_Cmd(0xC0 + (column - 1));
break;
case 3:
LCD_Cmd(0x90 + (column - 1));
break;
case 4:
LCD_Cmd(0xD0 + (column - 1));
break;
};
|
|
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Mon May 04, 2015 4:58 am |
|
|
You should look at the example LCD driver that CCS supplies( in the examples folder) as well as the 'flex_LCD' driver here in the code library that PCM_P cut. I've used the 'flex' version for years...solid,reliable code.
Jay |
|
![](templates/subSilver/images/spacer.gif) |
pic.programmer
Joined: 30 Apr 2015 Posts: 29 Location: Banned - spammer
|
|
Posted: Mon May 04, 2015 5:41 am |
|
|
I will try those LCD drivers. Mine doesn't use LCD_RW line. Also with my code any pin combination can be used for LCD. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Mon May 04, 2015 7:19 am |
|
|
The 'flex' driver can use any combination of pins and RW is not required.
I've only used it on one project as I needed a few more bytes of RAM and used the LCD RAM for a couple variables.
Jay |
|
![](templates/subSilver/images/spacer.gif) |
ELCouz
Joined: 18 Jul 2007 Posts: 427 Location: Montreal,Quebec
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Tue May 05, 2015 12:33 am |
|
|
Yes, with a fast display, and a PIC24, using a timer interrupt. In fact I did this on a display over thirty years ago. The particular code also locks you to using PMP.
For 8bit mode on any other port, you may as well just use the CCS LCD driver. This already supports a well written 8bit mode.
For 4bit mode, the key thing about flex_lcd, is that it is _flexible_. You can use just about any combination of pins. Not using R/W, means you are back to having to assume the worst for all the timings (which is what flex_lcd does if the R/W pin is not used). If you want the speed advantage of 8bit mode, you have to use the R/W pin and poll the display, or manually program the delays needed by the particular display (and beware if you do this to make sure you are choosing the 'worst case' timings).
It does strike a little of 're-inventing the wheel'. |
|
![](templates/subSilver/images/spacer.gif) |
pic.programmer
Joined: 30 Apr 2015 Posts: 29 Location: Banned - spammer
|
|
Posted: Tue May 05, 2015 2:24 am |
|
|
I think flex_lcd is better than my code, because the flex_lcds LCD print function can print floating point but mine only prints strings. So, if int or float has to be printed with mine than they have to be first converted to string. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Tue May 05, 2015 3:16 am |
|
|
Lets say one thing.
Well done for actually posting some code.
We 'suffer' from 90% of the posters here wanting everything written for them, without actually trying to program, so it is really nice to have somebody else arriving and offering routines....
Any display routine, can be used with the CCS printf. It's one of CCS's 'great little features'. You can have a routine that sends a value over something not normally use for display, like (perhaps) I2C, and if the routine to display a single character, is called 'display', you can just have the code:
Code: |
float val=123.4;
printf(display,"Val is :- %5.2f",val);
|
and the text, and the decoded number is all sent automatically to the 'display' routine. Really cracking ability, and one that after a while becomes essential!... |
|
![](templates/subSilver/images/spacer.gif) |
jeremiah
Joined: 20 Jul 2010 Posts: 1329
|
|
Posted: Tue May 05, 2015 6:07 am |
|
|
Just to add on to what Ttelmah said, when using the version 5 compilers, you can also make the printf look more like a method out of your lcd driver.
Starting with version 5 (I *think* v4 does not support this), you can use what are called variadic macros. Google that if you want to know more, but the short of it:
Code: |
#define lcd_printf(fmt,...) printf(display,fmt,__VA_ARGS__)
|
Code: |
void main(void){
//do init stuff
//say hello
lcd_printf("Hello World\n");
lcd_printf("value=%d",3);
while(TRUE);
}
|
It basically allows for any number of inputs. The ... puts all other parameters into the __VA_ARGS__ spot.
I like doing this more for debug (because then I can #define all the debug printfs out really cleanly) but I also like to use it for making functions fit their driver naming for organizational purposes. I also find it useful because my customers tend to add/change requirements on me late and sometimes the naming of my streams doesn't make as much sense anymore with the new configuration. You only have to change the stream name in one place which is nice. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Tue May 05, 2015 7:17 am |
|
|
It 'began' to appear in the late V4 compilers. Variable arguments is part of ANSI C, and hence CCS added it. Before about 4.100 none of it worked. By the late V4 versions parts were working (though I don't think macro support had appeared). I don't think the macros worked till quite a few versions into V5 (5.010 possibly). |
|
![](templates/subSilver/images/spacer.gif) |
|