CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

I dont understand this piece of code from LCD.c driver

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jet_pack234



Joined: 11 Feb 2005
Posts: 11

View user's profile Send private message Send e-mail

I dont understand this piece of code from LCD.c driver
PostPosted: Thu Sep 22, 2005 4:39 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Sep 22, 2005 5:52 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Thu Sep 22, 2005 7:59 am     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Thu Sep 22, 2005 8:05 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group