M4X
Newbie level 3
Hello everybody :smile:
Being a beginner in the [wanderful ^^] world of MCUs, I've been doing some simulations in ISIS with mikroC code as application to various tutorials found on the net before buying any real kit/programmer...
Lately I was interested in interfacing PICs and LCDs without using mikroC's LCD_Library, it worked perfectly [after many tries, of course :wink: ] when I used a PIC16F84A and the LM020L [both found in ISIS's library] to display some "Hello world" stuff...
So I tried to do something more interesting with a PIC18F4550: reading 4 analog and 16 digital inputs, and then displaying the values on the LCD
But things didn't work at all, from the beginning, when I first tried to display some text on the LCD: I'm not sure, but I think it's something related to the PIC18F4550 features that I don't nedd to use [comparators and other stuff that I don't understand, yet...], or maybe it is some wrong mikroC project config, or even a clock/oscillator issue since ISIS tells me that the LCD "received command whilst busy"
Here are the mikroC PRO for PIC 4.60 and Proteus ISIS 7.7 projects: View attachment PIC18F4550_LCD.zip
And for those who don't want to download it :wink: :
ISIS Schematic:
**broken link removed**
mikroC Code:
prog.c
lcd_interfacing.h
lcd_interfacing.c
Thanks in advance for your help.
Being a beginner in the [wanderful ^^] world of MCUs, I've been doing some simulations in ISIS with mikroC code as application to various tutorials found on the net before buying any real kit/programmer...
Lately I was interested in interfacing PICs and LCDs without using mikroC's LCD_Library, it worked perfectly [after many tries, of course :wink: ] when I used a PIC16F84A and the LM020L [both found in ISIS's library] to display some "Hello world" stuff...
So I tried to do something more interesting with a PIC18F4550: reading 4 analog and 16 digital inputs, and then displaying the values on the LCD
But things didn't work at all, from the beginning, when I first tried to display some text on the LCD: I'm not sure, but I think it's something related to the PIC18F4550 features that I don't nedd to use [comparators and other stuff that I don't understand, yet...], or maybe it is some wrong mikroC project config, or even a clock/oscillator issue since ISIS tells me that the LCD "received command whilst busy"
Here are the mikroC PRO for PIC 4.60 and Proteus ISIS 7.7 projects: View attachment PIC18F4550_LCD.zip
And for those who don't want to download it :wink: :
ISIS Schematic:
**broken link removed**
mikroC Code:
prog.c
Code:
#include "lcd_interfacing.h"
void main()
{
//OSCCON = 0x72;
//T1CON = 0x00;
CMCON = 0x07; // deactivate comparators
ADCON1 = 0x0B; // RA0-RA3: Analog, the rest: Digital, voltage references: Vss and Vdd
ADCON2 &= 0x80; // Adc_read() will return a right-justified binary value
// Input
TRISA |= 0x0F; // Analog: RA0-RA3: In
TRISB = 0x0F; // Digital buttons: RB4-RB7: Out, RB0-RB3: In
// Output
TRISC &= 0x00; // LCD Command: RC0-RC2: Out
TRISD = 0x00; // LCD Data: RD0-RD7: Out [some functions, like LCD_Wait_BF()
// might need RD0-RD7: In, but they restore it Out when finished]
// Misc
//TRISE |= 0x07; // we could use it later, I don't know...
LCD_Init_LCD();
}
lcd_interfacing.h
Code:
sbit LCD_RS at RC0_bit;
sbit LCD_RW at RC1_bit;
sbit LCD_EN at RC2_bit;
/*
sbit LCD_D0 at RD0_bit;
sbit LCD_D1 at RD1_bit;
sbit LCD_D2 at RD2_bit;
sbit LCD_D3 at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;
*/
sbit LCD_BF at RD7_bit;
#define LCD_Data PORTD
#define LCD_Data_Direction TRISD
void LCD_Wait_BF ();
void LCD_Init_LCD ();
void LCD_Write_Command (unsigned char cmd);
void LCD_Write_Data (unsigned char dat);
void LCD_Write_String (unsigned char* str);
lcd_interfacing.c
Code:
#include "lcd_interfacing.h"
void LCD_Wait_BF ()
{
TRISD = 0xFF;
LCD_RS = 0;
LCD_RW = 1;
LCD_EN = 1;
while (LCD_BF)
{
LCD_EN = 0;
LCD_EN = 1;
}
LCD_EN = 0;
TRISD = 0x00;
}
void LCD_Init_LCD ()
{
LCD_Write_Command(0x34); // 8-bit interface, 1 line, 5x10-dot font
LCD_Write_Command(0x0E); // Display ON, Cursor ON, Blink OFF
//LCD_Write_Command(0x01); // clear dispalay
LCD_Write_Command(0x06); // Entry Mode: I/D: 1 [increment], S: 0 [don't accompany display shift]
LCD_Write_Command(0x80); // set DDRAM adress
LCD_Write_Data('M');
}
void LCD_Write_Command (unsigned char cmd)
{
LCD_Data = cmd;
LCD_RS = 0;
LCD_RW = 0;
LCD_EN = 1;
LCD_EN = 0;
LCD_Wait_BF();
}
void LCD_Write_Data (unsigned char dat)
{
LCD_Data = dat;
LCD_RS = 1;
LCD_RW = 0;
LCD_EN = 1;
LCD_EN = 0;
LCD_Wait_BF();
}
void LCD_Write_String(unsigned char* str)
{
while (str[0] != '\0')
{
LCD_Write_Data(str[0]);
str++;
}
}
Thanks in advance for your help.
M4X.