PIC F873A - Page 1
Forum section: electronics / general

author: donthack22
author_rank: Contributor
timestamp: March 06, 2019, 09:28:55 pm
content: Hello ! I am trying to implement a "Hello World" program on my picf873a. I did it in proteus and it works, but when i use it in reality it shows nothing. I use a 20mhz crystal quartz on pins 9 10, . I connected pins 8 and 19 to GND,pins 28 to 21 to DB7 to DB0. I also connected pin 12 to E and pin 11 to RS. RW is connected to ground, same as VSS. VDD is at 5v and i control V0 using a pot. A is on 5v and k is on ground aswell. I attached the program, maybe anyone could point me on what i am doing wrong.

author: Andy Watson
author_rank: Super Contributor
timestamp: March 07, 2019, 01:27:51 am
content: Schematic ? Or even some indication of what the PIC is driving ?From your description I am guessing that you are using a 1620 type display, or one of its derivatives. These are slow devices - especially if of dubious provinence - study the datasheet for the display and ensure that all your timings are very generous. In particular these displays can take considerable time to complete their reset cycle. Also, your "Enable" function appears to strobe the eneable signal in two instruction cycles of the PIC - with a 20MHz clock this is probably much too fast for the display.

author: donthack22
author_rank: Contributor
timestamp: March 07, 2019, 09:10:27 am
content: I am driving a 1602A QAPASS. I ll try to make the enable function take longer.

author: picandmix
author_rank: Frequent Contributor
timestamp: March 07, 2019, 09:38:30 am
content: Have you got your VEE connected like this pic shows ?When you rotate the 10k trimmer can you produce the 'blocks' as in the second pic or does the screen remain blank at all times ?What are you programming your Pic chip with , and once programmed have you Read it back by doing a Verify to ensure its programmed in ok ?What have you built the circuit on, a breadboard ?If so a common problem is that leads of the crystal and its caps are so thin they do not make good contact in the breadboard.If so, solder then together onto some thicker wire and plug those into the board.Always keep those wires as short as possible and close to the pics pins, not on long leads etc.

author: donthack22
author_rank: Contributor
timestamp: March 07, 2019, 09:43:15 am
content: I use a pickit3 to rpogram, if i verify after i program it says "Verification succsesful". I do not see the black boxes no matter how i switch the pot, i only see the LCD turned on, with a blue screen.

author: StillTrying
author_rank: Super Contributor
timestamp: March 07, 2019, 10:14:42 am
content: It looks like there's only a 5ms delay between power up and sending commands to the LCD, 15ms to 100ms is recommended.

author: picandmix
author_rank: Frequent Contributor
timestamp: March 07, 2019, 10:15:31 am
content: If you are not getting those blocks then the screen is not working correctly.Connections between the pic and lcd are a very common problem area for a first circuit, so check your wiring very carefully including shorts between the lcd pins etc.To ensure your Pic circuit is also working have you run a LED flasher program ?

author: donthack22
author_rank: Contributor
timestamp: March 07, 2019, 11:51:43 am
content: I redid my code using the steps from herehttp://web.alfredstate.edu/faculty/weimandn/lcd/lcd_initialization/lcd_initialization_index.html. I increased the delay at the begining. I also get a black boxes row, there was a faulty wire between pot and VEE.

author: mikerj
author_rank: Super Contributor
timestamp: March 07, 2019, 12:55:47 pm
content: Are you disabling the PGM pin in the config settings?

author: picandmix
author_rank: Frequent Contributor
timestamp: March 07, 2019, 01:13:26 pm
content: Ok, good you have found the lcd fault.Best if you can load up this flasher code, it is what I have used before as a 4 second flasher, but using a 4mhz crystal, so have changed the OSC to HS for your 20mhz crystal which should flash about once per second.You can measure the output on any port B pin with a DVM or led and resistor etc.

author: donthack22
author_rank: Contributor
timestamp: March 07, 2019, 02:58:40 pm
content: Sadly the program doesnt work, so certainly something that i do is wrong. I uploaded the program in a new MPLAB IDE project and i CLEAN & BUILD it and i uploaded the hex file to the PIC through PICKIT3. I used a led that doesnt light up also i measured the outputs using a digital multimeter, and they are about 0.04 cosntant.

author: donthack22
author_rank: Contributor
timestamp: March 07, 2019, 03:00:13 pm
content: No i did not. Can you explain me what it is and how to do that please.

author: donthack22
author_rank: Contributor
timestamp: March 07, 2019, 03:12:22 pm
content: My fault again, i forgot to connect the VDD pin. The program works, the led is flashing and the output is from about 0.30V to 4.9 V.

author: donthack22
author_rank: Contributor
timestamp: March 07, 2019, 03:51:38 pm
content: I finally managed to do it guys. Thank you everybody, i listened to all of your advices and i fixed every issue. For future newbies as myself i will leave here a lsit of what i have changed hardware and software:1) Check all connections and faulty wires (one of problems was a faulty wire, another one was forgetting the vdd connection)2) Check that your microcontroller is working with a led flash program, like the one @picandmix provided, THANKS.3) The pins of the Crystal were indeed too tiny for a breadboard, so i soldered them with some wire.4) The enable sequence in my code was indeed too short for a 20MHz frequency, so i added a delay of 500ns routine that i called inside the enable routine (the enable should take above 450ns)

author: picandmix
author_rank: Frequent Contributor
timestamp: March 07, 2019, 04:43:50 pm
content: Well done !A couple of points, the 16F873A is the smallest of that family so most small programs for the 874/876/877 will run on it ok, depending on how many i/o pins are needed.You will find lots of example code for these old, but popular chips, though a 4mhz crystal is often needed for them, unless you modify the code.The code you use is running in lcd 8 bit mode, many other lcd routines just use the 4 bit mode , so saving i/o usage.This site l use 4 and 20mhz examples and a 4 bit lcd routine, the author is still around for help.http://www.winpicprog.co.uk/pic_tutorial_hardware.htmAs you advance you my find some of the more modern 16F chips with internal oscillators more handy.

author: macboy
author_rank: Super Contributor
timestamp: March 08, 2019, 03:46:30 pm
content: 4 bit mode is definitely worth implementing, to save 4 I/O pins. The two nibbles can be written back-to-back quickly so that the overall speed is hardly affected.I also always like to implement R/W capability so that I can read the busy flag. This can substantially speed up writing to the display, since you can simply check for busybeforewriting each byte/command, rather than hard-coding a delay after writing. This allows the PIC to run other code (like determining the next character to display) while the display is busy, rather than just spinning it wheels burning away a fixed worst-case wait time.

author: donthack22
author_rank: Contributor
timestamp: March 15, 2019, 11:13:31 pm
content: Hi again guy ! I am trying to implement the 4 bit connection and until now i just succeded to get weird characters on my lcd. Can u tell me please how can i send the letter which are writen with 8 bits, on a 4 bit connection?

author: picandmix
author_rank: Frequent Contributor
timestamp: March 15, 2019, 11:56:27 pm
content: Hi,Its all down to the lcd output routine you use, with 8 bit routine the character is sent out in one 8 bit operation, with a 4 bit routine the upper and lower 4 bits are sent one after another and are reconnected by the displays internal program.I have such a 4 bit lcd routine but its geared for a 4 mhz crystal, so unless you have one then look at that site I mentioned earlier which I think has a 4 bit 20mhz routine or search the web for a suitable one.

author: mariush
author_rank: Super Contributor
timestamp: March 16, 2019, 12:02:39 am
content: You also have to init the display differentlysee page 10 and 11 for example code to init and send data:http://www.newhavendisplay.com/specs/NHD-0208AZ-FL-GBW.pdfNote though that technically the 4bit code works, but it's not great.What I mean is that they still use a full 8 bit port as a variable, so if you have only 4 of the 8 pins of that port connected to the LCD, the code would overwrite the data on the other 4 pins instead of just modifying only the pins connected to lcd.You can change the code to get individual bits and put them on pins for example something like thisCode:// in a header file h file#defineLCD_RS PORTEbits.RE0#defineLCD_RW PORTEbits.RE1#define LCD_EN PORTEbits.RE2// for 4 bit mode (can be on different ports)#define LCD_DATA0 PORTAbits.RA4#define LCD_DATA1 PORTAbits.RA5#define LCD_DATA2 PORTAbits.RA6#define LCD_DATA3 PORTAbits.RA7// second lcd_en = 1 is just a delay, to keep LCD_EN =1 for 500ns when clock is 16Mhz// may want to change this to a function to add a proper delay if running at different frequencies#defineLCD_STROBE()((LCD_EN = 1),(LCD_EN = 1), (LCD_EN=0))// in a c file :// moves the 4bit values into the 4 individual pins (when lcd in 4bit mode) - not the most efficient but it does the jobvoid lcd_bits(unsigned char data) {LCD_DATA0 = data & 1;LCD_DATA1 = (data >> 1) & 1;LCD_DATA2 = (data >> 2) & 1;LCD_DATA3 = (data >> 3) & 1;}void lcd_write_4bit(unsigned char c) {LCD_RS = 1;LCD_RW = 0;lcd_bits(c >> 4);LCD_STROBE();lcd_bits(c );LCD_STROBE();LCD_RS = 0;delay_50us(); // custom delay function i wrote for 16 mhz, you can use your own or you can wait until lcd says it's no longer busy.}may find more useful data in controller datasheet (these displays use various chips that clone a hitachi chip,so command set is same, timings more or less same, but it's good idea to be conservative)Link:http://www.newhavendisplay.com/app_notes/ST7066U.pdfSee pages 23-28 for detailed 4bit and 8 bit initialization and sending data info.

author: picandmix
author_rank: Frequent Contributor
timestamp: March 16, 2019, 04:29:44 pm
content: If you have not sorted things, this works fine with my 873a and 20mhz xtal.Might seem a bit different to the code you already have, but lots of slightly different ways of handling the users data etc.

author: donthack22
author_rank: Contributor
timestamp: March 16, 2019, 08:44:58 pm
content: Thank you guys !

author: picandmix
author_rank: Frequent Contributor
timestamp: March 18, 2019, 08:45:13 pm
content: Did that 4 bit code work for you ?

author: donthack22
author_rank: Contributor
timestamp: March 19, 2019, 11:43:13 am
content: Sorry, i didnțt try your code. I am trying to do a project i found on the internet and it uses a 4bit LCD. In this project there is also a code provided, but there was a different LCD used. So i read your code and changed the project code, and it seems to work, but i didn't try your code separately.

author: picandmix
author_rank: Frequent Contributor
timestamp: March 19, 2019, 04:31:30 pm
content: No problem...