View previous topic :: View next topic |
Author |
Message |
geshsoft
Joined: 01 May 2007 Posts: 14 Location: California
|
LCD on PIC16F684 |
Posted: Tue May 01, 2007 10:03 pm |
|
|
Hi, I am new to CCSC - switched over from Hi-Tech by getting my hands on the CCSC 4 compiler. I have been trying to interface LCD in 4 bit mode but so far I have not been successful. I wrote the LCD routines myself - I did not use the built in driver. Here is the complete code I wrote:
#include "C:\Program Files\PICC\Projects\Tprobe\TProbe.h"
#use fast_io(A)
#byte PORTA = 0x05
//=============================================================================
void writeLCD(unsigned int c, unsigned int RS);
void lcdputs (int *s);
void lcdinit(void);
void lcdclear();
void strobeE();
//=============================================================================
void main()
{
unsigned int adcVal = 0;
set_tris_a(0x01); //RA0 - input
set_tris_c(0x00);
setup_adc_ports(sAN0|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_4);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_oscillator(OSC_8MHZ);
lcdinit();
lcdputs(*"HELLO");
set_adc_channel(0);
adcVal = read_adc();
}
//=============================================================================
void writeLCD(unsigned int c, unsigned int RS)
{
unsigned int upper = 0, lower = 0;
output_bit(PIN_C0, RS); //RS
output_bit(PIN_C1, 0); //R/W = 0, which is write
upper = (c & 0xF0) >> 2;
lower = (c & 0x0F) << 2;
PORTA = ((PORTA & 0x02) | upper);
strobeE();
PORTA = ((PORTA & 0x02) | lower);
strobeE();
delay_ms(2);
}
//=============================================================================
void strobeE()
{
output_bit(PIN_C2, 1);
delay_us(1);
output_bit(PIN_C2, 0);
delay_us(1);
}
//=============================================================================
void lcdinit(void)
{
delay_ms(20);
PORTA = ((PORTA & 0x02) | 0x0C); //Write 3 to bit 5 downto 2
strobeE();
delay_ms(5);
strobeE();
delay_us(160);
strobeE();
delay_ms(5);
PORTA = ((PORTA & 0x02) | 0x08); //Write 2 to bit 5 downto 2
strobeE();
delay_us(40);
writeLCD(0x28, 0); // 4 bit mode, 1/16 duty, 5x8 font
writeLCD(0x08, 0); // display off
writeLCD(0x0F, 0); // display on, blink cursor on
writeLCD(0x06, 0); // entry mode
}
//=============================================================================
void lcdclear()
{
writeLCD(0x1, 0); //writes 0x01 instruction
delay_ms(2); //wait to complete
}
//=============================================================================
void lcdputs (int *s)
{
while(*s)
{
writeLCD(*s++, 0);
}
}
//=============================================================================
The way it seems is that it fails initialization... I believe it is some small detail which I simply cannot catch since as I said it is my first time dealing with CCSC. My 4 data lines are supposed to be RA2 - RA5, RC0 is RS, RC1 is RW, and RC2 is E. Anybody seeing something wrong with what I am doing here? ![Rolling Eyes](images/smiles/icon_rolleyes.gif) |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue May 01, 2007 10:19 pm |
|
|
I didn't look at your code in detail, but I don't think this construct is yet
working in CCS:
Quote: | lcdputs(*"HELLO"); |
Also, it's normal to put a continuous while(1) loop at the end of main()
to prevent the code from executing the hidden SLEEP instruction that's
put there by the compiler. Hardware processes that are in progress
will be halted if the PIC executes a Sleep instruction.
Quote: |
lcdinit();
lcdputs(*"HELLO");
set_adc_channel(0);
adcVal = read_adc();
} |
|
|
![](templates/subSilver/images/spacer.gif) |
geshsoft
Joined: 01 May 2007 Posts: 14 Location: California
|
|
Posted: Tue May 01, 2007 10:37 pm |
|
|
Forget about the lcdpits() routine - I don't even get there. I should be able to see the cursor blinking after initialization which does not happen. I have done this routines in Hi Tech but this is my first time doing it in CCSC. I think maybe something is messing up my outputs and therefore the LCD interface? Hum, I did put the while(1) the code but there is really no change. I wish that was the solution though ![Confused](images/smiles/icon_confused.gif) |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue May 01, 2007 10:53 pm |
|
|
The quick way is just to use this one:
http://www.ccsinfo.com/forum/viewtopic.php?t=24661
Then test it with this:
lcd_init();
lcd_putc("Hello World");
Note that there is no '*' in front of the string.
Also, don't set the TRIS. Let the compiler handle it (for this test). |
|
![](templates/subSilver/images/spacer.gif) |
geshsoft
Joined: 01 May 2007 Posts: 14 Location: California
|
|
Posted: Tue May 01, 2007 11:27 pm |
|
|
Ok, maybe for now I can temporarily use this code but I would still like to know what I am missing in my code... Thanks though ![Very Happy](images/smiles/icon_biggrin.gif) |
|
![](templates/subSilver/images/spacer.gif) |
geshsoft
Joined: 01 May 2007 Posts: 14 Location: California
|
|
Posted: Thu May 03, 2007 12:54 am |
|
|
Ok, I found what the problem is... It was a little detail I overlooked - I used a pin that I did not use on my previous projects and this is MCLR which is either master clear or input, but never output as we all know. In my previous designs on hi-tech i used another pin instead so now I saw it. Other than that the routines I wrote work perfect, but I think we will need more than magic to make an input only pin to an output ![Laughing](images/smiles/icon_lol.gif) |
|
![](templates/subSilver/images/spacer.gif) |
|