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

pic 18F4550 - ccs-PCB - LCD communication "LM044L"

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



Joined: 26 Mar 2012
Posts: 16

View user's profile Send private message

pic 18F4550 - ccs-PCB - LCD communication "LM044L"
PostPosted: Mon Aug 27, 2012 7:00 am     Reply with quote

Hello,
I did some modification in LCD driver of the pic_c module to be able to use:
* port A : RA2 ... RA5 :for communication {4 bit mode}
* Pin RC0 for E
* Pin RC1 for RS
The other LCD Pins or related to the GND.

But the program did not work in reality and neither in simulation :/

Otherwise, when I use the PortB (RB2 ... RB5) pins for communication it work well !

The Code:
Code:

#include <18f4550.h>

#fuses HS,NOWDT,NOPROTECT,NOLVP,PUT,NOMCLR
#USE DELAY(CLOCK=20MHZ, CRYSTAL)

#byte porta = 0xF80
#byte portb = 0xF81
#byte portc = 0xF82
#byte portd = 0xF83
#byte porte = 0xF84
#byte trisa = 0xF92
#byte trisb = 0xF93
#byte trisc = 0xF94
#byte trisd = 0xF95
#byte trise = 0xF96

//lcd
#define En PIN_C0
#define RS PIN_C1

//LCD function
void clk (void)
{
   output_high(En);
   delay_us(1);
   output_low(En);
}
void send (int1 a,int8 data)//0 for commande ; 1 for data

   if (a) output_high(Rs);
   else output_low(Rs);
   porta=data>>2;
   clk();
   porta=data<<2;
   clk();
}
void init (void)
{
   output_low(Rs);porta=12;clk();delay_ms(5);//8 bit mode
   output_low(Rs);porta=12;clk();delay_ms(5);//8 bit mode
   output_low(Rs);porta=12;clk();delay_ms(5);//8 bit mode
   output_low(Rs);porta=8;clk();delay_us(40);//4 bit mode
   //configuration selon besoin
   send(0,0b00101100);delay_us(40);//mode 4 bit;4 ligne;caractere 5x10;
   send(0,0b00001100);delay_us(40);//affichage on; curseur off;blinottement off;
   send(0,0b00000001);delay_ms(2);//clear display
   send(0,0b00000110);delay_us(40);
}
void gotoxy(int8 x,int8 y)
{
   int8 adress;
   switch(y){
      case 1: adress=0x80;break;
      case 2: adress=0xC0;break;
      case 3: adress=0x94;break;
      case 4: adress=0xD4;break;
   }
   adress+=x-1;
   send(0,adress);
   delay_us(40);
}
void clear(void)
{
   send(0,1);
   delay_ms(20);//X10
}
void write(char c)
{
   send(1,c);
   delay_us(40);
}
//fin lcd

void main()
{
   porta=0;
   portb=0;
   portc=0;
   portd=0;
   porte=0;
   trisa=0b00000011;
   trisb=0b00000000;
   trisc=0b10111000;
   trisd=0b00001111;
   trise=0b11111111;
-----------------------------------------
  delay_ms(1000);
  init();
  gotoxy(1,1);
  write('a');delay_ms(1000);
  write('b');delay_ms(1000);
  gotoxy(5,1);write('c');delay_ms(1000);
  gotoxy(1,2); write('d');delay_ms(1000);
  gotoxy(8,1);write('e');delay_ms(1000);
  write('f');delay_ms(1000);
  gotoxy(10,3);write('f');delay_ms(1000);
  gotoxy(20,4);write('g');delay_ms(1000);
  while(1);
}
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Aug 27, 2012 9:00 am     Reply with quote

...providing your code worked 100% with real hardware....

Possible reasons include

I/O pin default setup to another use. Most pins have several uses and need to be disabled.....

incorrect use of set_tris.....function( inputs reallly an output,etc)
wrong setup time for the LCD(though you did say the code did work...)
error in wiring(easy to do....btdt !)
contrast not set right...


the 'flex_LCD driver' does work ,so you might want to look at it..


hth
jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19540

View user's profile Send private message

PostPosted: Mon Aug 27, 2012 9:19 am     Reply with quote

1) Use flex lcd. Written, works, only needs you to change the pin definition table, to use _any_ combination of port pins. Safer, simpler.
2) ADC. This will default to enabled on the PORT_A pins. You are not turning this off.
Code:

#include <18f4550.h>

#fuses HS,NOWDT,NOPROTECT,NOLVP,PUT,NOMCLR
#USE DELAY(CLOCK=20MHZ, CRYSTAL)

#include <flex_lcd.c>
//edit the pin definitions in the above file to:
#define LCD_DB4   PIN_A2
#define LCD_DB5   PIN_A3
#define LCD_DB6   PIN_A4
#define LCD_DB7   PIN_A5

#define LCD_E     PIN_C0
#define LCD_RS    PIN_C1
#define LCD_RW    PIN_C0

//#define USE_LCD_RW   1    //Must be remmed out

void main(void) {
  setup_adc_ports(NO_ANALOGS);
  delay_ms(1000);
  lcd_init();
  lcd_gotoxy(1,1);
  lcd_putc('a');delay_ms(1000);
  lcd_putc('b');delay_ms(1000);
  lcd_gotoxy(5,1);
  lcd_putc('c');delay_ms(1000);
  lcd_gotoxy(1,2);
  lcd_putc('d');delay_ms(1000);
  lcd_gotoxy(8,1);
  lcd_putc('e');delay_ms(1000);
  lcd_puc('f');delay_ms(1000);
  lcd_gotoxy(10,3);
  lcd_putc('f');delay_ms(1000);
  lcd_gotoxy(20,4);
  lcd_putc('g');delay_ms(1000);
  while(1);
}


Best Wishes
Louati



Joined: 26 Mar 2012
Posts: 16

View user's profile Send private message

PostPosted: Mon Aug 27, 2012 2:19 pm     Reply with quote

Yeah the flex_lcd do work Smile thank you Smile
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