• 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

Active 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.
 

skimask87

Member
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:

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
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
 

camerart

Active Member
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.
 

skimask87

Member
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?
 

camerart

Active Member
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.
 

Inquisitive

Super Moderator
How was it solved?
 

camerart

Active Member
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

skimask87

Member
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?
 

skimask87

Member
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?
 

camerart

Active Member
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.
 

camerart

Active Member
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

Last edited:

skimask87

Member
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.
 

camerart

Active Member
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

EE World Online Articles

Loading
Top