View previous topic :: View next topic |
Author |
Message |
jet_pack234
Joined: 11 Feb 2005 Posts: 11
|
I dont understand this piece of code from LCD.c driver |
Posted: Thu Sep 22, 2005 4:39 am |
|
|
Hi,
Having dumped my own LCD driver code I'm going to use the LCD.c driver included in ccs. I pretty much understand what its all doing apart from the following code. Would be extremely grateful if someone could explain it to me. Thanks.
Code: |
#if defined(__PCH__)
#if defined use_portb_lcd
#byte lcd = 0xF81 // This puts the entire structure
#else
#byte lcd = 0xF83 // This puts the entire structure
#endif
#else
#if defined use_portb_lcd
#byte lcd = 6 // on to port B (at address 6)
#else
#byte lcd = 8 // on to port D (at address 8)
#endif
#endif |
|
|
|
Paolino
Joined: 19 Jan 2004 Posts: 42
|
|
Posted: Thu Sep 22, 2005 5:52 am |
|
|
CCS wrote this driver which can be easly used on PIC16 and PIC18. Those PIC families can have (depend on the device type) PORTB and PORTD and you can select where connect your LCD. For example, using PIC 16F876 or PIC18F252 you can only select PORTB, but with 16F877 or 18F452 you can select PORTD too. This is your choice, obviuosly!
I think you have omitted a part of the LCD driver code:
Code: |
// Un-comment the following define to use port B
// #define use_portb_lcd TRUE
|
If you connect LCD to PORTB, you must un-comment the "#define use_portb_lcd TRUE" line.
So,
Code: | #if defined(__PCH__) // if PIC18 family compiler
#if defined use_portb_lcd // if LCD is connect to PORTB
#byte lcd = 0xF81 // this is the address used by the struct in the driver
#else // else
#byte lcd = 0xF83 // this one is the address
#endif
#else // else, if PIC16 family compiler
#if defined use_portb_lcd // if LCD is connect to PORTB
#byte lcd = 6 // LCD is on to port B (at address 6)
#else
#byte lcd = 8 // else it is on to port D (at address 8)
#endif
#endif |
Hope this helps.
Paolo. |
|
|
jet_pack234
Joined: 11 Feb 2005 Posts: 11
|
|
Posted: Thu Sep 22, 2005 7:59 am |
|
|
But where does the oxf81 come in? I am using port b on a 16f84a, is this the address of this port or something? |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Thu Sep 22, 2005 8:05 am |
|
|
YES. use 0x6 for port B
look at page 8
http://ww1.microchip.com/downloads/en/DeviceDoc/35007b.pdf
- - - - - - - - - - - - -
#byte takes a variable and puts it at a given location
ie:#byte lcd = 0xF81
means make me a variable "lcd" and store it at 0xF81.
AND
0xF81 happens to be where a port is((look this up in spec, this is NOT for PIC 16f84a))
So
It has the effect of overlaying a variable LCD 'ON PHYSICAL PINS'
so if you have tris set right you can read or write to the pins.
tris=0x00 //all outputs
and lcd=0b00000001
would make port all grounded except pin 0.
pin 0= +5 |
|
|
|