Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC doesn't run with internal oscillator

Status
Not open for further replies.

camerart

Well-Known Member
Hi,

I'm trying to get a 16F819 to run with a 4X20 LCD screen using it's internal oscillator.

The program uses the pins where a XTL would be used.

Here is the code:
Define CONF_WORD = 0x3f72 'internal oscillator
Define CLOCK_FREQUENCY = 4 'Changed from 12
AllDigital
ADCON1 = 0x0e

Define SIMULATION_WAITMS_VALUE = 1 'SIMULATION ONLY

Define LCD_BITS = 8
Define LCD_DREG = PORTA
Define LCD_DBIT = 0
Define LCD_RSREG = PORTB
Define LCD_RSBIT = 0
Define LCD_RWREG = PORTB
Define LCD_RWBIT = 1
Define LCD_EREG = PORTB
Define LCD_EBIT = 2
Define LCD_READ_BUSY_FLAG = 1
Lcdinit

Dim an0 As Word

loop:
Adcin 0, an0
Lcdcmdout LcdClear
Lcdout "Analog input AN0"
Lcdcmdout LcdLine2Home
Lcdout "Value: ", #an0
Toggle RB4
WaitMs 250
Goto loop

Can anyone suggest why it doesn't run? or can I change the used XTL pins so that Ican use a XTL?

Camerart.
 
Wish I could put this in a way that would effectively convey the thought that I am speaking very slowly...

I am asking nicely.... Please try and be helpful WITHOUT the sarcasm!!!
 
Last edited by a moderator:
camerart Try to start using the identifiers when using the config bits...
Define CONF_WORD = 0x3f72 'internal oscillator.... This is wrong!!!!


0x3F72 means RC osc is on... MCLR is on, brown out and power up are on

If you need internal oscillator then use 0x3F50 for MCLR as digital pin and both osc pins as digital.
Use 0x3F70 for MCLR on...

Also include

OSCCON = 0x70 to set the internal OSC to 4Mhz
 
Wish I could put this in a way that would effectively convey the thought that I am speaking very slowly...

I am asking nicely.... Please try and be helpful WITHOUT the sarcasm!!!

Hi, You mentioned an indicator LED in your message, I used one all afternoon, but didn't post that code.

Cheers, Camerart.
 
Hi, You mentioned an indicator LED in your message, I used one all afternoon, but didn't post that code.

Cheers, Camerart.
That would've been helpful to know...
Got anything hooked up to the contrast pin?

EDIT: Is this on a simulator? Or do you have actual hardware hooked up?
 
That would've been helpful to know...
Got anything hooked up to the contrast pin?

EDIT: Is this on a simulator? Or do you have actual hardware hooked up?

Actually, I looked again and the Toggle is the LED indicator.

Contrast to GND at the moment.

First in the simulator second with hardware.
 
How was it solved?
 
I've tried various combinations, of configurations, but failed. I've now added a crystal and changed to 16F648A (I don't need analogue inputs)

I have attached a program that works, with the main LCD part commented out as a test, so the XTL and chip are working, but with the LCD connected and un-commented, it doesn't work, no LED flashing either. It all works in the Oshonsoft simulator.
 

Attachments

  • LCD on XTL 16F648A 150414 2035 LED ONLY WORKING.bas
    566 bytes · Views: 318
So, works in the simulator, and not on actual hardware...is that correct?
And what is your "actual hardware"?
Got a schematic you care to share with the rest of the world?
Maybe a few pictures to go along with it?
 
So, let's review...

1st post...
Code:
.........
AllDigital   ---- ok all digital
ADCON1 = 0x0e   ---- ok RA0 is an analog pin

Define SIMULATION_WAITMS_VALUE = 1 'SIMULATION ONLY

Define LCD_BITS = 8    ---- ok, 8 bit LCD interface
Define LCD_DREG = PORTA   ---- Hmmmm......Port A - all 8 bits go out to the LCD.  Wait a minute, didn't you just set RA0 to be an analog input?  Hmmmm....
Define LCD_DBIT = 0
Define LCD_RSREG = PORTB
Define LCD_RSBIT = 0
Define LCD_RWREG = PORTB
Define LCD_RWBIT = 1
Define LCD_EREG = PORTB
Define LCD_EBIT = 2
Define LCD_READ_BUSY_FLAG = 1
Lcdinit

Dim an0 As Word

loop:
Adcin 0, an0
Lcdcmdout LcdClear
Lcdout "Analog input AN0"
Lcdcmdout LcdLine2Home
Lcdout "Value: ", #an0
Toggle RB4
WaitMs 250
Goto loop

See anything wrong?
 
So, let's review...

1st post...
Code:
.........
AllDigital   ---- ok all digital
ADCON1 = 0x0e   ---- ok RA0 is an analog pin

Define SIMULATION_WAITMS_VALUE = 1 'SIMULATION ONLY

Define LCD_BITS = 8    ---- ok, 8 bit LCD interface
Define LCD_DREG = PORTA   ---- Hmmmm......Port A - all 8 bits go out to the LCD.  Wait a minute, didn't you just set RA0 to be an analog input?  Hmmmm....
Define LCD_DBIT = 0
Define LCD_RSREG = PORTB
Define LCD_RSBIT = 0
Define LCD_RWREG = PORTB
Define LCD_RWBIT = 1
Define LCD_EREG = PORTB
Define LCD_EBIT = 2
Define LCD_READ_BUSY_FLAG = 1
Lcdinit

Dim an0 As Word

loop:
Adcin 0, an0
Lcdcmdout LcdClear
Lcdout "Analog input AN0"
Lcdcmdout LcdLine2Home
Lcdout "Value: ", #an0
Toggle RB4
WaitMs 250
Goto loop

See anything wrong?
Yes, I have swapped it round a few times, and #11 should be the last.
 
PICSIM.jpg
SCH.gif
Post your schematic.
Post the code in the message.
Is the Ra1 pin output as default?

I added the TRIS's to make them all output.
The image shows incorrect readout in the SIM, but I tried again and it is OK.
I looked up schematics similar to the one I posted, I used R/W, but I've tried swapping the pins and ports around quite a bit as tests. Are there any wiring configurations that should not be used? Iadded a XTL after trying with out.
I assume you mean post HEX?
 

Attachments

  • LCD on XTL 16F648A 160414 1000.hex
    906 bytes · Views: 259
Last edited:
So, works in the simulator, and not on actual hardware...is that correct?
And what is your "actual hardware"?
Got a schematic you care to share with the rest of the world?
Maybe a few pictures to go along with it?
 

Attachments

  • PICLCD.jpg
    PICLCD.jpg
    294.3 KB · Views: 364
Maybe you go back thru and re-do your wiring and your program completely.
First look at the wiring for the circuit shows me 5 immediate problems for sure, and another 4 possible problems.
First look at the code shows me another 4 problems that don't match up to the circuit with 9 possible problems.
 
Maybe you go back thru and re-do your wiring and your program completely.
First look at the wiring for the circuit shows me 5 immediate problems for sure, and another 4 possible problems.
First look at the code shows me another 4 problems that don't match up to the circuit with 9 possible problems.
Maybe you go back thru and re-do your wiring and your program completely.
First look at the wiring for the circuit shows me 5 immediate problems for sure, and another 4 possible problems.
First look at the code shows me another 4 problems that don't match up to the circuit with 9 possible problems.

I'm rewiring it, but from those immediate wiring problems you can see, can you give me any clues, so I don't simply repeat my mistakes? I hope you are looking at the program I posted in #16? Noting that the schematic posted is only a guide, as I have changed it since.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top