mariale442
Newbie level 2
pic18f4620 lcd
I'm migrating my PIC18F452 code to a PIC18F4620 and I'm stuck with the LCD code. What was working fine in the 452 now is not in the 4620.
Does anybody encountered with this sort of problems.
It is prety much important for me to make this thing work so any kind of help would be appreciated.
Thank you all.
Added after 16 minutes:
This is my code.
I don't know which is the problem
-----------------------------------------------------------------------------------------------
this is the source file:
-----------------------------------------------------------------------------------------------
#include "lcdconfig.h"
#include <p18f4620.h>
VOID lcd_wait ();
VOID lcd_init ();
VOID wrcmd (CHAR);
VOID pause(INT num)
// Utility routine to pause for
// a period of time.
{ while(num--)
{/*do nothing */
}
}
VOID lcd_init()
// Initialise the LCD Display.
{ PORTA = TRISA = 0;
TRISB = PORTB = 0xFF;
ADCON1 = 7;
wrcmd(0x30); // 8-bit mode - 1 line.
wrcmd(LCD_SETVISIBLE+0x04); // Display only - no cursors.
wrcmd(LCD_SETMODE+0x02); // Automatic Increment - Display shift left.
wrcmd(LCD_SETDDADDR+0x0F); // Initial Position far right.
}
VOID clearscreen ()
// Clear the LCD Screen and reset
// initial position.
{ wrcmd(LCD_CLS);
wrcmd(LCD_SETDDADDR+0x00);
}
/***** Utility Functions *****/
// Write a command to the LCD display.
VOID wrcmd (CHAR cmdcode)
{ TRISB = 0;
PORTB = cmdcode;
// Write to PORTB to latch data into the display.
// Toggle Pin 'E' to send the command.
PORTA = LCD_CMD_WR;
PORTA |= E_PIN_MASK;
Nop();
PORTA &= ~E_PIN_MASK;
lcd_wait();
}
VOID wrdata (CHAR data)
// Write a Character to the LCD Display.
{ TRISB = 0;
PORTB = data;
PORTA = LCD_DATA_WR;
PORTA |= E_PIN_MASK;
Nop();
PORTA &= ~E_PIN_MASK;
lcd_wait();
}
// Wait for the LCD busy flag to clear.
VOID lcd_wait ()
{ BYTE status;
TRISB = 0xFF;
PORTA = LCD_BUSY_RD;
do
{ PORTA |= E_PIN_MASK;
Nop();
status = PORTB;
PORTA &= ~E_PIN_MASK;
} while (status & 0x80);
}
CHAR buf [16]="1. Consultar ";
// Initialise our variables and call the
// Assembly routine to initialise the LCD display.
VOID calc_display (CHAR buf[16])
// Use the Output and Clearscreen routines from the
// *LCD_Write* assembly file to output ASCII values to the LCD.
{ INT8 i;
clearscreen();
for (i=0 ; i<strlen(buf); i++)
// { if (buf[calc_testkey(buf) || buf == 0x2D)
{
wrdata(buf);
pause(5000);
}
// }
}
VOID main (VOID)
{ lcd_init();
calc_display(buf);
}
-----------------------------------------------------------------------------------------------
this is the header file:
-----------------------------------------------------------------------------------------------
typedef void VOID;
typedef int INT;
typedef signed char INT8;
typedef signed int INT16;
typedef signed long INT32;
typedef unsigned short WORD;
typedef char CHAR;
typedef unsigned char BYTE;
typedef double FLOAT;
typedef long LONG;
typedef INT8 BOOL;
//LCD Config
#define MAX_DISPLAY_CHAR 16
//LCD Registers addresses (PORT B)
#define LCD_CMD_WR 0x00
#define LCD_DATA_WR 0x01
#define LCD_BUSY_RD 0x02
#define LCD_DATA_RD 0x03
//LCD Commands
#define LCD_CLS 0x01
#define LCD_HOME 0x02
#define LCD_SETMODE 0x04
#define LCD_SETVISIBLE 0x08
#define LCD_SHIFT 0x10
#define LCD_SETFUNCTION 0x20
#define LCD_SETCGADDR 0x40
#define LCD_SETDDADDR 0x80
#define E_PIN_MASK 0x04
#define FALSE 0
#define TRUE 1
--------------------------------------------------------------------------------------------
help meeeeeee...
I'm migrating my PIC18F452 code to a PIC18F4620 and I'm stuck with the LCD code. What was working fine in the 452 now is not in the 4620.
Does anybody encountered with this sort of problems.
It is prety much important for me to make this thing work so any kind of help would be appreciated.
Thank you all.
Added after 16 minutes:
This is my code.
I don't know which is the problem
-----------------------------------------------------------------------------------------------
this is the source file:
-----------------------------------------------------------------------------------------------
#include "lcdconfig.h"
#include <p18f4620.h>
VOID lcd_wait ();
VOID lcd_init ();
VOID wrcmd (CHAR);
VOID pause(INT num)
// Utility routine to pause for
// a period of time.
{ while(num--)
{/*do nothing */
}
}
VOID lcd_init()
// Initialise the LCD Display.
{ PORTA = TRISA = 0;
TRISB = PORTB = 0xFF;
ADCON1 = 7;
wrcmd(0x30); // 8-bit mode - 1 line.
wrcmd(LCD_SETVISIBLE+0x04); // Display only - no cursors.
wrcmd(LCD_SETMODE+0x02); // Automatic Increment - Display shift left.
wrcmd(LCD_SETDDADDR+0x0F); // Initial Position far right.
}
VOID clearscreen ()
// Clear the LCD Screen and reset
// initial position.
{ wrcmd(LCD_CLS);
wrcmd(LCD_SETDDADDR+0x00);
}
/***** Utility Functions *****/
// Write a command to the LCD display.
VOID wrcmd (CHAR cmdcode)
{ TRISB = 0;
PORTB = cmdcode;
// Write to PORTB to latch data into the display.
// Toggle Pin 'E' to send the command.
PORTA = LCD_CMD_WR;
PORTA |= E_PIN_MASK;
Nop();
PORTA &= ~E_PIN_MASK;
lcd_wait();
}
VOID wrdata (CHAR data)
// Write a Character to the LCD Display.
{ TRISB = 0;
PORTB = data;
PORTA = LCD_DATA_WR;
PORTA |= E_PIN_MASK;
Nop();
PORTA &= ~E_PIN_MASK;
lcd_wait();
}
// Wait for the LCD busy flag to clear.
VOID lcd_wait ()
{ BYTE status;
TRISB = 0xFF;
PORTA = LCD_BUSY_RD;
do
{ PORTA |= E_PIN_MASK;
Nop();
status = PORTB;
PORTA &= ~E_PIN_MASK;
} while (status & 0x80);
}
CHAR buf [16]="1. Consultar ";
// Initialise our variables and call the
// Assembly routine to initialise the LCD display.
VOID calc_display (CHAR buf[16])
// Use the Output and Clearscreen routines from the
// *LCD_Write* assembly file to output ASCII values to the LCD.
{ INT8 i;
clearscreen();
for (i=0 ; i<strlen(buf); i++)
// { if (buf[calc_testkey(buf) || buf == 0x2D)
{
wrdata(buf);
pause(5000);
}
// }
}
VOID main (VOID)
{ lcd_init();
calc_display(buf);
}
-----------------------------------------------------------------------------------------------
this is the header file:
-----------------------------------------------------------------------------------------------
typedef void VOID;
typedef int INT;
typedef signed char INT8;
typedef signed int INT16;
typedef signed long INT32;
typedef unsigned short WORD;
typedef char CHAR;
typedef unsigned char BYTE;
typedef double FLOAT;
typedef long LONG;
typedef INT8 BOOL;
//LCD Config
#define MAX_DISPLAY_CHAR 16
//LCD Registers addresses (PORT B)
#define LCD_CMD_WR 0x00
#define LCD_DATA_WR 0x01
#define LCD_BUSY_RD 0x02
#define LCD_DATA_RD 0x03
//LCD Commands
#define LCD_CLS 0x01
#define LCD_HOME 0x02
#define LCD_SETMODE 0x04
#define LCD_SETVISIBLE 0x08
#define LCD_SHIFT 0x10
#define LCD_SETFUNCTION 0x20
#define LCD_SETCGADDR 0x40
#define LCD_SETDDADDR 0x80
#define E_PIN_MASK 0x04
#define FALSE 0
#define TRUE 1
--------------------------------------------------------------------------------------------
help meeeeeee...