Author Topic: PIC F873A  (Read 1367 times)

0 Members and 1 Guest are viewing this topic.

Offline donthack22

  • Contributor
  • Posts: 21
  • Country: ro
PIC F873A
« on: March 06, 2019, 09:28:55 pm »
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.
 

Offline Andy Watson

  • Super Contributor
  • ***
  • Posts: 1718
Re: PIC F873A
« Reply #1 on: March 07, 2019, 01:27:51 am »
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.
 

Offline donthack22

  • Contributor
  • Posts: 21
  • Country: ro
Re: PIC F873A
« Reply #2 on: March 07, 2019, 09:10:27 am »
I am driving a 1602A QAPASS. I ll try to make the enable function take longer.
 

Offline picandmix

  • Frequent Contributor
  • **
  • Posts: 395
  • Country: gb
Re: PIC F873A
« Reply #3 on: March 07, 2019, 09:38:30 am »
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.





 

Offline donthack22

  • Contributor
  • Posts: 21
  • Country: ro
Re: PIC F873A
« Reply #4 on: March 07, 2019, 09:43:15 am »
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.
 

Offline StillTrying

  • Super Contributor
  • ***
  • Posts: 2268
  • Country: se
  • Country: Broken Britain
Re: PIC F873A
« Reply #5 on: March 07, 2019, 10:14:42 am »
It looks like there's only a 5ms delay between power up and sending commands to the LCD, 15ms to 100ms is recommended.
CML+  That took much longer than I thought it would.
 

Offline picandmix

  • Frequent Contributor
  • **
  • Posts: 395
  • Country: gb
Re: PIC F873A
« Reply #6 on: March 07, 2019, 10:15:31 am »
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 ?
 

Offline donthack22

  • Contributor
  • Posts: 21
  • Country: ro
Re: PIC F873A
« Reply #7 on: March 07, 2019, 11:51:43 am »
I redid my code using the steps from here http://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.
 

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 2175
  • Country: gb
Re: PIC F873A
« Reply #8 on: March 07, 2019, 12:55:47 pm »
Are you disabling the PGM pin in the config settings?
 

Offline picandmix

  • Frequent Contributor
  • **
  • Posts: 395
  • Country: gb
Re: PIC F873A
« Reply #9 on: March 07, 2019, 01:13:26 pm »
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.

 
The following users thanked this post: donthack22

Offline donthack22

  • Contributor
  • Posts: 21
  • Country: ro
Re: PIC F873A
« Reply #10 on: March 07, 2019, 02:58:40 pm »
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.
 

Offline donthack22

  • Contributor
  • Posts: 21
  • Country: ro
Re: PIC F873A
« Reply #11 on: March 07, 2019, 03:00:13 pm »
No i did not. Can you explain me what it is and how to do that please. 
 

Offline donthack22

  • Contributor
  • Posts: 21
  • Country: ro
Re: PIC F873A
« Reply #12 on: March 07, 2019, 03:12:22 pm »
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.
 

Offline donthack22

  • Contributor
  • Posts: 21
  • Country: ro
Re: PIC F873A
« Reply #13 on: March 07, 2019, 03:51:38 pm »
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)
 

Offline picandmix

  • Frequent Contributor
  • **
  • Posts: 395
  • Country: gb
Re: PIC F873A
« Reply #14 on: March 07, 2019, 04:43:50 pm »
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.htm

As you advance you my find some of the more modern  16F chips with internal oscillators more handy.
 
The following users thanked this post: Circlotron

Offline macboy

  • Super Contributor
  • ***
  • Posts: 1978
  • Country: ca
Re: PIC F873A
« Reply #15 on: March 08, 2019, 03:46:30 pm »
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 busy before writing 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.
 

Offline donthack22

  • Contributor
  • Posts: 21
  • Country: ro
Re: PIC F873A
« Reply #16 on: March 15, 2019, 11:13:31 pm »
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?
 

Offline picandmix

  • Frequent Contributor
  • **
  • Posts: 395
  • Country: gb
Re: PIC F873A
« Reply #17 on: March 15, 2019, 11:56:27 pm »
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.
« Last Edit: March 16, 2019, 12:01:40 am by picandmix »
 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 3833
  • Country: ro
  • .
Re: PIC F873A
« Reply #18 on: March 16, 2019, 12:02:39 am »
You also have to init the display differently

see page 10 and 11 for example code to init and send data: http://www.newhavendisplay.com/specs/NHD-0208AZ-FL-GBW.pdf
Note 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 this 
Code: [Select]
// in a header file h file

    #define LCD_RS PORTEbits.RE0
    #define LCD_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

    #define LCD_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 job
void 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.pdf
See pages 23-28 for detailed  4bit and 8 bit initialization and sending data info.
« Last Edit: March 16, 2019, 12:05:16 am by mariush »
 

Offline picandmix

  • Frequent Contributor
  • **
  • Posts: 395
  • Country: gb
Re: PIC F873A
« Reply #19 on: March 16, 2019, 04:29:44 pm »
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.



 

Offline donthack22

  • Contributor
  • Posts: 21
  • Country: ro
Re: PIC F873A
« Reply #20 on: March 16, 2019, 08:44:58 pm »
Thank you guys !
 

Offline picandmix

  • Frequent Contributor
  • **
  • Posts: 395
  • Country: gb
Re: PIC F873A
« Reply #21 on: March 18, 2019, 08:45:13 pm »
Did that 4 bit code work for you ?
 

Offline donthack22

  • Contributor
  • Posts: 21
  • Country: ro
Re: PIC F873A
« Reply #22 on: March 19, 2019, 11:43:13 am »
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.
 

Offline picandmix

  • Frequent Contributor
  • **
  • Posts: 395
  • Country: gb
Re: PIC F873A
« Reply #23 on: March 19, 2019, 04:31:30 pm »
No problem... :)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf