|
|
View previous topic :: View next topic |
Author |
Message |
Moezzz
Joined: 18 Jun 2012 Posts: 5
|
|
Posted: Mon Jun 18, 2012 2:59 am |
|
|
PCM programmer wrote: | Here is a test program and an LCD driver for the PicDem 4 board.
I don't have a PicDem 4 board to test this code on. But I compiled
their MPASM firmware and programmed it into a 16F628, and then
I looked at the I/O Expander signals with a logic analyzer. The
signals produced by the code below look very similar to the Microchip
firmware. So I think it has a good chance to work. I did this with
vs. 4.106 of the CCS compiler.
Many of the delays used in the LCD driver are very long. I think
they are much longer than is really needed. But, the Microchip
firmware has these long delays in it, so I kept them the same
in the code below. Also, I kept the init values exactly the same.
Here's the test program. It should be saved as "PicDem4_Test.c".
It's the main source program for the project.
Code: |
#include <16F628.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
// We can't use the hardware UART at the same time as the LCD
// because they share pin B1.
//#use rs232(baud=9600, xmit=PIN_B2, rcv=PIN_B1, ERRORS)
#include "PicDem4_lcd.c" // This is the PicDem 4 LCD driver
#define PICDEM4_PERIPH_CS PIN_B3
// The RS-232 level converter chips, LIN bus transceiver,
// and Motor Driver chip on the PicDem4 board are all
// enabled or disabled by one PIC pin (Pin B3).
#define disable_peripherals() output_low(PICDEM4_PERIPH_CS)
#define enable_peripherals() output_high(PICDEM4_PERIPH_CS)
//==========================
void main()
{
disable_peripherals();
delay_ms(1000); // Start-up delay for i/o expander
lcd_init(); // Always call this first.
printf(lcd_putc,"Hello World\n");
printf(lcd_putc,"This is line 2");
delay_ms(2000);
printf(lcd_putc,"\fHi There\n");
printf(lcd_putc,"PicDem4 LCD");
while(1);
}
|
This is the LCD driver. It should be saved as "PicDem4_lcd.c".
Code: |
// This is a PicDem4 LCD driver for the CCS compiler.
// This driver writes to the LCD by writing to the
// I/O Expander on the PicdDem4 board, using SPI.
// The LCD is connected to the I/O Expander.
#define SDO PIN_B1 // SPI data
#define SCK PIN_B4 // SPI clock
#define LCD_E_BITMASK 0x10
#define LCD_RS_BITMASK 0x40
#define LCD_LINE2_ADDRESS 0x40
// The value is transmitted MSB first, in SPI Mode 2,
// to the I/O Expander chip on the PicDem4 board.
void spi_write_byte(int8 value)
{
int8 i;
for(i = 0; i < 8; i++)
{
output_low(SDO);
output_high(SCK);
if(bit_test(value, 7))
output_high(SDO);
else
output_low(SDO);
value <<= 1;
delay_us(4);
output_low(SCK);
delay_us(6);
}
output_low(SDO);
}
//----------------------------------------------
void lcd_send_nibble(int8 address, int8 value)
{
value &= 0x0F;
if(address)
{
value |= LCD_RS_BITMASK;
}
SPI_write_byte(value);
delay_us(5);
SPI_write_byte(value | LCD_E_BITMASK);
delay_us(5);
SPI_write_byte(value);
delay_us(5);
}
//----------------------------------------------
// Send one byte to the LCD via the I/O expander.
void lcd_send_byte(int8 address, int8 value)
{
delay_ms(40); // Possibly this delay can be reduced
lcd_send_nibble(address, value >> 4); // Send high nibble first
lcd_send_nibble(address, value & 0x0F);
}
//--------------------------------
void lcd_init(void)
{
output_low(SCK);
output_low(SDO);
delay_ms(1);
spi_write_byte(0x00); // Init I/O Expander
delay_ms(150);
lcd_send_nibble(0, 3);
delay_ms(40);
lcd_send_nibble(0, 3);
delay_ms(1);
lcd_send_nibble(0, 3);
delay_ms(1);
lcd_send_nibble(0, 2);
delay_ms(40);
lcd_send_byte(0, 0x28); // Function set
lcd_send_byte(0, 0x0D); // Display = ON
lcd_send_byte(0, 0x01); // Display clear
lcd_send_byte(0, 0x06); // Entry Mode
lcd_send_byte(0, 0x80); // DDRAM address 0
}
//----------------------------
void lcd_gotoxy(int8 x, int8 y)
{
int8 address;
if(y != 1)
address = LCD_LINE2_ADDRESS;
else
address=0;
address += x-1;
lcd_send_byte(0, 0x80 | address);
}
//----------------------------------------
void lcd_putc(char c)
{
switch(c)
{
case '\f':
lcd_send_byte(0,1);
delay_ms(2);
break;
case '\n':
lcd_gotoxy(1,2);
break;
case '\b':
lcd_send_byte(0,0x10);
break;
default:
lcd_send_byte(1,c);
break;
}
}
|
|
code tested on picdem 4 with 16F628A but it doesn't work . I'm using same configuration RB4 clk and RB1 DATA |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jun 18, 2012 12:38 pm |
|
|
I still don't have a PicDem 4 LCD board to test.
All I can do is to go through the project again, and program a PIC with
their i/o expander code, and use a 16F628A for the master, and look at
the signals again. I check and see if I made any mistakes. I can't do that
today, but I can do it tomorrow afternoon.
What's your compiler version ? It's a 4-digit number like in this link:
http://www.ccsinfo.com/devices.php?page=versioninfo
It's given at the top of the .LST file, which will be in your project directory
after a successful compile. |
|
|
Moezzz
Joined: 18 Jun 2012 Posts: 5
|
|
Posted: Mon Jun 18, 2012 2:10 pm |
|
|
thanks for your reply
Quote: | What's your compiler version ? |
I use CCS PCH C Compiler, Version 4.120 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jun 19, 2012 12:33 am |
|
|
I want to be certain about what board you are using. Post a link to the
web page for your board. |
|
|
Moezzz
Joined: 18 Jun 2012 Posts: 5
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jun 19, 2012 3:14 pm |
|
|
According to the PicDem 4 user's guide, to use the LCD, you need to
install jumpers on both J8 and J10, on the upper 2 pins on each one.
Also, you need to remove the jumper on J21.
Quote: |
A.14 LCD DISPLAY
For LCD operation, these jumpers must be configured as follows:
PIC16:
J8/10 - Upper two pins ON
J21 - OFF (PORTB LEDs)
|
Have you done all of this ? |
|
|
Moezzz
Joined: 18 Jun 2012 Posts: 5
|
|
Posted: Wed Jun 20, 2012 2:43 am |
|
|
Jumper J8 and J10 are correctly configured I'm using RB4 and RB1 for CLK and DATA and jumper J21 is removed
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jun 20, 2012 12:23 pm |
|
|
I have put in a request with Microchip support for a copy of the .HEX file
for the I/O Expander chip (U3 - PIC16LF72) on the PicDem 4 board.
We'll see if they are willing to give it to me. If they do, I can program
a 16LF72 with it and put it on one of my PicDem2-Plus boards. Then I can
jumper the lcd to use the same circuit as on PicDem 4, and then I can test
the C driver for the LCD.
So it might be a few days before they respond. I'll update this thread
with the results when they do. |
|
|
Moezzz
Joined: 18 Jun 2012 Posts: 5
|
|
Posted: Mon Jul 09, 2012 3:12 am |
|
|
PCM programmer wrote: | I have put in a request with Microchip support for a copy of the .HEX file
for the I/O Expander chip (U3 - PIC16LF72) on the PicDem 4 board.
We'll see if they are willing to give it to me. If they do, I can program
a 16LF72 with it and put it on one of my PicDem2-Plus boards. Then I can
jumper the lcd to use the same circuit as on PicDem 4, and then I can test
the C driver for the LCD.
So it might be a few days before they respond. I'll update this thread
with the results when they do. |
nothing new? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jul 09, 2012 11:31 am |
|
|
I put in a trouble ticket on June 20th and just a couple days ago, they
changed the status from "pending" to "In Process". So maybe they
will give me an answer within another two weeks. At least I hope so.
The latest word from them as of late July, is they're still working on it.
They say the board is old and they're having trouble finding the
information on it.
I just got their final statement on July 31. They say they asked around
the company (Microchip) and they can't find anyone who has the Hex
file for the i/o expander on the PicDem4 board. So they can't help. |
|
|
stinky
Joined: 05 Mar 2012 Posts: 99 Location: Central Illinois
|
|
Posted: Mon Mar 11, 2013 11:30 am |
|
|
Just wanted to chime in on this one because I just had success with the PICDEM 4 LCD display.
PCM's code does work.
I reduced the delay time inside his lcd_send_byte function that is included in his code "PicDem4_lcd.c".
He actually commented that "possibly this delay can be reduced"
I changed:
Code: | void lcd_send_byte(int8 address, int8 value)
{
delay_ms(40); // Possibly this delay can be reduced
lcd_send_nibble(address, value >> 4); // Send high nibble first
lcd_send_nibble(address, value & 0x0F);
} |
To This:
Code: | void lcd_send_byte(int8 address, int8 value)
{
delay_ms(4); //Reduced this delay from 40ms
lcd_send_nibble(address, value >> 4); // Send high nibble first
lcd_send_nibble(address, value & 0x0F);
} |
I am so giddy that I can finally use this board to do useful things that I thought I would share.
PCM, thanks are again in order. |
|
|
|
|
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
|