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 CCS Technical Support

Some LCD
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Julspower
Guest







Some LCD
PostPosted: Sun Feb 17, 2008 9:50 pm     Reply with quote

Hi

first the code
Code:

/*
   Fichier:Encoder.c   
   Date: 7 FEV 2008     
   Auteur: Julien Gingras     
   Revision: 1.0
   Compilation:
            Compilateur: CCS
            Version:     3.5.0.92
            Librairies: 

*/

/*                 ***** LISTE DES INCLUDES *****                            */

#CASE   // Met le compilateur CASE SENSITIVE

#include <18F1220.h>   // Fichier correspondant à notre PIC

#fuses INTRC_IO, NOPUT, NOBROWNOUT, NOWDT, NOCPD, NOWRTD, NOWRTC, NOEBTR, NOEBTRB, NOPROTECT, NOCPB, NOWRTB, DEBUG
#BYTE OSCCON = 0x8F        
#use delay(clock=8000000)   // Fixer la vitesse de l'horloge
                     // Permet d'utiliser delay_ms() et delay_us()       


/*                **** LISTE DES CONSTANTES *****                           */

//command lines
#define RS_LCD PIN_A2
#define RW_LCD PIN_A3
#define E_LCD PIN_A1

//Data bus
#define D0 PIN_B0
#define D1 PIN_B1
#define D2 PIN_B2
#define D3 PIN_B3
#define D4 PIN_B4
#define D5 PIN_B5
#define D6 PIN_A4
#define D7 PIN_A6

#define RC5_INPUT PIN_A7 //This is the only one remaining

//we can't use B6 and B7 because they are use by ICD2   

/*            **** LISTE DES VARIABLES GLOBALES *****                       */




/*               ***** LISTE DES PROTOTYPES *****                           */

void main(void);
void InitPic(void);
void InitLCD(void);
void SendLCDCMD(int8 nData);
void SendLCDData(int8 nData);
void GOTOLCD(int x, int y);
void PulseEnable(void);
void WaitBusy(void);

/*               ***** PROGRAMME PRINCPAL *****                             */

void main(void)
{           
   OSCCON=0x71;
   
    InitPic();
   InitLCD();
   
   SendLCDData("I Love Nat");
   SendLCDCMD(0xC0);
   //GOTOLCD(0,1);
   //SendLCDData("Appuie!!!!");
   while(1)
   {
      output_toggle(PIN_A0);
      delay_ms(100);
   }

}

/**********************************************************************************
Nothing to yet
Port are set automaticly
We set a timer for the RC5
***********************************************************************************/
void InitPic(void)
{   
/*   //Set interupt for two ext on different edge
   disable_interrupts(GLOBAL);
   ext_int_edge(0, L_TO_H);
   ext_int_edge(1, H_TO_L);
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_EXT);
   enable_interrupts(INT_EXT1);
*/
   //Set timer 0 in 16 bit to count the uS between input
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8);
   set_timer0(0);
}


/*Wait the busy to end by checking it, then Init the lcd the way we want to*/
void InitLCD(void)
{
   SendLCDCMD(0x20);         //Function Set
   delay_ms(6);
   SendLCDCMD(0x20);         //Function Set
   delay_us(101);
   SendLCDCMD(0x20);         //Function Set
   WaitBusy();
   SendLCDCMD(0x38);         //Function Set
   WaitBusy();
   SendLCDCMD(0x08);         //Display OFF
   SendLCDCMD(0x01);         //Clear display
   SendLCDCMD(0x08);         //Entry mode set
   SendLCDCMD(0x0D);         //Display ON
   SendLCDCMD(0x02);         //Home   
}


/*send the command and pulse enable*/
void SendLCDCMD(int8 nData)
{
   //Mean Write command
   output_bit(RS_LCD, 0);
   output_bit(RW_LCD, 0);
   
   //Convert the int8 to bit on the port A and B
   output_bit(D0, nData&0x01);
   output_bit(D1, (nData>>1)&0x01);
   output_bit(D2, (nData>>2)&0x01);
   output_bit(D3, (nData>>3)&0x01);
   output_bit(D4, (nData>>4)&0x01);
   output_bit(D5, (nData>>5)&0x01);
   output_bit(D6, (nData>>6)&0x01);
   output_bit(D7, (nData>>7)&0x01);

   //Exec
   PulseEnable();
   delay_ms(16);
}

/*Send data and pulse the enable*/
void SendLCDData(int8 nData)
{
   //Mean Write data
   output_bit(RS_LCD, 1);
   output_bit(RW_LCD, 0);
   
   //Convert the int8 to bit on the port A and B
   output_bit(D0, nData&0x01);
   output_bit(D1, (nData>>1)&0x01);
   output_bit(D2, (nData>>2)&0x01);
   output_bit(D3, (nData>>3)&0x01);
   output_bit(D4, (nData>>4)&0x01);
   output_bit(D5, (nData>>5)&0x01);
   output_bit(D6, (nData>>6)&0x01);
   output_bit(D7, (nData>>7)&0x01);

   //Exec
   PulseEnable();

   //Wait until he is ready for another command
   delay_ms(16);
}


/*This function place the cursor at the x,y pos */
void GOTOLCD(int x, int y)
{
   int nAdr;
   
   switch(y)
   {
      case 0:
      nAdr = 0;
      break;
      case 1:
      nAdr = 0x40;
      break;
      case 2:
      nAdr = 0x14;
      break;
      case 3:
      nAdr = 0x55;
      break;
   }
   nAdr += x;
   SendLCDCMD(nAdr|0x80);
}

/*Pulse the enable line of the LCD to make it read the data bus*/
void PulseEnable(void)
{
   delay_ms(1);
   output_bit(E_LCD, 1);
   delay_ms(2);
   output_bit(E_LCD, 0);
   delay_ms(1);
}


/*Wait the busy flag from the LCD to turn off*/
void WaitBusy(void)
{
   int1 bBusy;

   output_bit(RW_LCD, 1);
   output_bit(RS_LCD, 0);
      
   do
   {
      PulseEnable();
      delay_us(50);
      bBusy = input(D7);
   }while(bBusy==TRUE);
}


I know that flex driver but I would like to use mine

first question is
SendLCDData("I Love Nat");
why can i use this and it actually work???

this function is only waiting a char not a char*
and no where i made a test to know if its the end of the string and stop sending char

question 2:
why my
SendLCDCMD(0xC0); line doesn t work

its the command to move the cursor to the second line of the lcd
when i do it i lose the cursor and dont know where it is
but when i try to move it onthe first line everything work fine

thanks for your help guys
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 17, 2008 10:03 pm     Reply with quote

Quote:
Compilateur: CCS
Version: 3.5.0.92

That's not the compiler version. The version is a 4-digit number in
this format: x.xxx
Look at this page to see examples of compiler version numbers:
http://www.ccsinfo.com/devices.php?page=versioninfo
To find the compiler version, look at the start of the .LST file for
your project. The .LST file is in your project directory.

Quote:
#BYTE OSCCON = 0x8F

That's not the address of the OSCCON register. All registers in the 18F
PICs have three hex digits. Download the 18F1220 data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/39605F.pdf
Look in this section to find the true address of the OSCCON register.
Quote:
SPECIAL FUNCTION REGISTERS
JulsPower
Guest







PostPosted: Mon Feb 18, 2008 5:54 am     Reply with quote

oh ill check about the osccon register

for the version i will try to update it
but considering im home and use it for personal project i can t afford the real and lastest version :P

could my lcd initialised in 1 line only?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 18, 2008 12:08 pm     Reply with quote

I don't want you to upgrade the compiler, I want you to post the
version number. "3.5.0.92" is not a CCS compiler version number.
Look at the .LST file for your project. The version number is given
at the start of the file. Look below. I have vs. 4.068:
Code:

CCS PCM C Compiler, Version 4.068, xxxxx      17-Feb-08 13:47

               Filename: pcm_test.lst

               ROM used: 20 words (0%)
                         Largest free fragment is 2048
               RAM used: 8 (2%) at main() level
                         8 (2%) worst case
               Stack:    0 locations

Look at your .LST file and post your compiler version.
Julspower
Guest







PostPosted: Mon Feb 18, 2008 8:29 pm     Reply with quote

CCS PCH C Compiler, Version 3.200, 16465

Filename: Encoder.LST

ROM used: 720 bytes (18%)
Largest free fragment is 3376
RAM used: 6 (2%) at main() level
8 (3%) worst case
Stack: 4 locations


this is my version
ok someone told me what ccs was doing with a function that wait a char and you give it a string
it automaticly do it one at the time
i didn t know it :P

then
Im still not able to make the second line to show something
like the lcd was configured in 1 line only
what did i do wrong?
Julspower
Guest







PostPosted: Mon Feb 18, 2008 9:15 pm     Reply with quote

Code:
void InitLCD(void)
{
   delay_ms(16);
   SendLCDCMD(0x38);         //Function Set
   SendLCDCMD(0x28);         //Function Set
   delay_ms(16);
   SendLCDCMD(0x38);         //Function Set
   delay_ms(16);
   SendLCDCMD(0x38);         //Function Set
   delay_ms(16);
   SendLCDCMD(0x0D);         //Display ON
   SendLCDCMD(0x06);         //Entry mode set
   SendLCDCMD(0x01);         //Clear display
   SendLCDCMD(0x02);         //Home   
}



My init lcd looks like this now
in the three first function set im force to put 0x28 to the second one
if i put 0x38 there or 0x30 it fail to show anything

I made some test and the lcd is configured as a 1 line
but im sure there is two :P
any idea?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 18, 2008 9:35 pm     Reply with quote

Quote:
CCS PCH C Compiler, Version 3.200

This is the first version after CCS made some large changes in the
compiler. That version might have lots of bugs. Examples:
Quote:

3.200 A/D built in functions overhauled to support the newest chips (see readme.txt)
3.200 PCW device editor updated to support new chip features including dsPIC
3.200 New RFID drivers added
3.200 PIC18 optimization has been improved
3.200 #build has been added to allow location of reset and interrupt vectors
3.200 #build also allows the specification of external ROM on PIC18 parts
3.202 A problem with the definition of external ROM is now fixed
3.202 The extra NOP FFFF inserted for some chips is now removed by default
3.202 An optimization bug dealing with the BSR is fixed in the PIC18
3.202 The <<= and >>= operators on the PIC18 with int32's no longer corrupt memory
3.202 The +P command line option was failing on some systems, this is fixed
3.202 SET_PWMx_DUTY broke in 3.200 is now fixed
3.202 Some reported problems with the Bootloader examples are fixed
3.203 Floating point multiply for PIC18 is now much faster
3.203 A bug in 3.202 accessing bit fields in constant structures is fixed
3.203 Some optimization bugs including one involving & is fixed
3.204 Optimization bug from 2.203 is fixed
3.204 Missing nibble on larger addresses in the LST file is fixed
3.204 Date/Time added to the LST file
3.204 Support for Timer 5 added
3.205 A #OPT 9 optimization bug has been fixed
3.205 Some formatting issues with %e are fixed
3.206 A problem with the 16F688 UART is fixed
3.206 A PIC18 problem with constant bit fields in structures is fixed
3.206 New function INPUT_STATE() added to read a pin without changing the pin to input
3.207 Some new features added to setup_uart for the newest PIC parts
3.207 A bug involving some constant array references in an ISR is fixed
3.207 The number of error messages is now limited to 100
3.207 Bit operations with == and != are now more optimized
3.207 A bug with input_e() and output_e() is fixed
3.208 A bug involving (bit_test(...)==x) is fixed
3.208 Some PIC18 optimization problems are fixed, including problems with larger constant arrays
3.208 WRITE_PROGRAM_MEMORY was broke on some parts and is now fixed
3.208 The PCW version number is now synchronized with the compilers
3.209 An error 217 after compiling programs for large ROM chips is fixed
3.210 A bug in the printf %f is fixed
3.210 A PIC18 problem with arrays exactly 256 bytes is fixed
3.210 Updates for the newest chips
3.210 The \ line continuation character is now accepted for all preprocessor directives


Do you have a 20x4 LCD or a 16x2 LCD ?
I suggest that you try the Flex driver for your LCD. If it works, then
try your driver.
Julspower
Guest







PostPosted: Mon Feb 18, 2008 9:51 pm     Reply with quote

I have updated
CCS PCH C Compiler, Version 4.013, 28193 18-févr.-08 22:41

Filename: Encoder.lst

ROM used: 638 bytes (20%)
Largest free fragment is 2626
RAM used: 6 (2%) at main() level
8 (3%) worst case
Stack: 4 locations

I will try the flex driver to see what it give
atm i have a 16x2
but i might use a 16x4 one day

flex driver is only in 4-bit mode??

and why when I init the lcd i can t use 0x38 for the three first function set i have to put 0x28???? the bit removed is the data lenght
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 18, 2008 10:22 pm     Reply with quote

Yes, the Flex driver is only in 4-bit mode. Try it. If it works, then
your hardware is OK.
JulsPower



Joined: 18 Feb 2008
Posts: 11

View user's profile Send private message

PostPosted: Tue Feb 19, 2008 9:13 pm     Reply with quote

:(
ok
I modified by code to this
Code:

#CASE               // Met le compilateur CASE SENSITIVE
#include <18F1220.h>          // Fichier correspondant à notre PIC

#fuses INTRC_IO, NOPUT, NOBROWNOUT, NOWDT, NOCPD, NOWRTD, NOWRTC, NOEBTR, NOEBTRB, NOPROTECT, NOCPB, NOWRTB, DEBUG   
#use delay(clock=8000000)      // Fixer la vitesse de l'horloge
                        // Permet d'utiliser delay_ms() et delay_us()       
#use standard_io(A)
#use standard_io(B)
#include "Flex_LCD420.c"      //LCD driver

/*                **** LISTE DES CONSTANTES *****                           */

#define RC5_INPUT PIN_A7

//we can t use B6 and B7 because they are use by ICD2   

/*            **** LISTE DES VARIABLES GLOBALES *****                       */




/*               ***** LISTE DES PROTOTYPES *****                           */

void main(void);
void InitPic(void);

/*               ***** PROGRAMME PRINCPAL *****                             */

void main(void)
{           
    InitPic();

   lcd_init();
   // Clear the LCD.
   printf(lcd_putc, "\f");
   delay_ms(500);

   printf(lcd_putc, "\fThis is the 1st line");
      printf(lcd_putc, "\nNext is the 2nd line");
      printf(lcd_putc, "\nThis is the 3rd line");
      printf(lcd_putc, "\nFinally the 4th line");
      delay_ms(3000);

   while(1)
   {
      output_toggle(PIN_A4);
      delay_ms(100);
   }

}

/**********************************************************************************
Nothing to yet
Port are set automaticly
We set a timer for the RC5
***********************************************************************************/
void InitPic(void)
{   
   //Set timer 0 in 16 bit to count the uS between input
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8);
   set_timer0(0);
}


I also connect a new 20*4 LCD and use the flex driver for it
im using a 18f1220
I doubled check my wires
the contrast is set to 1.5V

and it still doesn t show anything:(
what could be the problem?
the wire going to the lcd are too long (around 5 inch)
when im in debug mode the data line have the right data on them

thanks to help me guys
i tried everything so help would be nice

I also have a 18f458 should i try with it?
Could it be a fuse i set or one i forgot?

I also have to say its powered over my icd2
and i run with the internal osc
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 19, 2008 10:47 pm     Reply with quote

Quote:
I also connect a new 20*4 LCD and use the flex driver for it
im using a 18f1220
I doubled check my wires
the contrast is set to 1.5V

and it still doesn t show anything:(
what could be the problem?
the wire going to the lcd are too long (around 5 inch)
when im in debug mode the data line have the right data on them

1. Post the list of #define statements at the start of the 20x4 driver
that show your pin connections.

2. Set the contrast to 0.5 volts.

3. Don't run it in debug mode. Run it in normal mode.
JulsPower



Joined: 18 Feb 2008
Posts: 11

View user's profile Send private message

PostPosted: Wed Feb 20, 2008 5:44 am     Reply with quote

i change this to have only port b for cmd line rs, rw, e
dont work :(

#define LCD_DB4 PIN_B4
#define LCD_DB5 PIN_B5
#define LCD_DB6 PIN_A0
#define LCD_DB7 PIN_A6

#define LCD_RS PIN_B0
#define LCD_RW PIN_B1
#define LCD_E PIN_B3

its also not working in normal mode :(

im using mplab if it help you :D
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 20, 2008 9:40 am     Reply with quote

Quote:

#fuses INTRC_IO, NOPUT, NOBROWNOUT, NOWDT, NOCPD, NOWRTD, NOWRTC, NOEBTR, NOEBTRB, NOPROTECT, NOCPB, NOWRTB, DEBUG

Get rid of the DEBUG fuse and add the NOLVP fuse.
esa



Joined: 31 Jan 2008
Posts: 19

View user's profile Send private message

PostPosted: Wed Feb 20, 2008 1:01 pm     Reply with quote

Dear julien,
I also make my one code to control a 4x20 LCD characters.
- The code is for 4 bits interface.
- The LCD can be write and read ( to read a password for example entered by a keyboard )
- The LCD can be wired on a PIC PORT ( PORT A-D ) or on a PCF8574 ( I2C )
- simply change a line to switch the code from I2C to PIC PORT.
I can post the code if it's could help you.
Regards
Eric
JulsPower



Joined: 18 Feb 2008
Posts: 11

View user's profile Send private message

PostPosted: Wed Feb 20, 2008 1:23 pm     Reply with quote

could you configure the line on different port? like the flex??


oh and i check its a 16x4 lcd
shouldn t change anything only the char i see
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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