Jump to content
Sign in to follow this  
Terry

16f818

Recommended Posts

Im just about to start programming the 16f818 for the first time. Dose anyone have any code I can use to help me get started ? Something simple using the ADC would be perfect.

I hate starting from scratch, its so easy to get something tiny wrong and then nothing works......

Thanks, Terry

Share this post


Link to post
Share on other sites

Have you looked through the app notes at the microchip site? They should have generic PIC16F A/D code there.

Share this post


Link to post
Share on other sites

Yes I have been reading all I can. I havent even got to the A/D code yet Im still stuck on getting the internal oscilator working :(

Terry

Share this post


Link to post
Share on other sites

There's nothing much to do with the INTOSC, just set the fuses correctly and copy the Flash's last address into OSCCAL at startup.

Share this post


Link to post
Share on other sites

Are you sure ? Unlike the 12f508 that I have been using there in no value in the last flash address.

I have set the OSCCON to 01100000 but I may have the config wrong as I have it as INTRC_IO, what do you think ?

Thanks, Terry

Share this post


Link to post
Share on other sites

As set you should have a 4MHz clock running your PIC. That's true, it seems they've dropped the OSCCAL on the newer devices. Not that bad actually, saves from losing it :P

Are you sure your PIC isn't running?

Share this post


Link to post
Share on other sites

Well as sure as I can be, I have it flashing the LED with the external res then change the code to internal and it just sits there.

Terry

Share this post


Link to post
Share on other sites

For some reason its not using the internal oscillator, what config word should I be using ?

Terry

Share this post


Link to post
Share on other sites

From what I see the FOSC<2:0> bits in the config word should be '100' (internal RC, no clock output).

But there's one thing I don't get, when you mention "change the code", do you mean by reprogramming the PIC or in the running software? Oscillator selection can only be done by reprogramming the config word with the programmer :unsure:

Share this post


Link to post
Share on other sites

I just mean change the config line from XT to INTRC_IO but for some reason its not working.

Terry

Share this post


Link to post
Share on other sites

Well, if the OSCCON is correct I'll give up... If you're programming in assembly, are you sure you've set the correct register page before setting its value? It's a pretty common mistake... and the default setting will set the RC oscillator at the slowest setting, maybe making your program appear stuck while it's infact running but very slowly...

Share this post


Link to post
Share on other sites

Mmh, nothing obvious to me... I'd maybe try skipping the oscillator stable wait...

Do you have another chip handy? Might be a defect too... I've once had one that wouldn't set one of the pins high unless I would do 2 consecutive writes :blink:

Share this post


Link to post
Share on other sites

Yep tryed 2 chips and without the wait lines. Im thinking it maybe my programmer.

Terry

Share this post


Link to post
Share on other sites

OK Kilrah I got it, I needed to turn off the MCLR bit in the config. I knew it would be something daft, I wasted hours on that....

Terry

Share this post


Link to post
Share on other sites

Ouch... OK, makes sense as MCLR doesn't have an internal pullup, it would always reset... Now what I wonder is why it worked with XT setting?

Share this post


Link to post
Share on other sites

Hmmm, I dont know, although its even odder than that because it would run in INTRC mode with a resonator connected.

Anyway I need to sort out the propper program now and what I thought was a simple job has turned out to be a very big flow chart so its not so simple after all.

Terry

Share this post


Link to post
Share on other sites

Something odd going on !

Im just trying to get to grips with the 10bit ADC. I find both ADRESL and ADRESH are always the same, the only way to change between the high and low bits is to change from page0 to page1. Any ideas ?

Terry

Share this post


Link to post
Share on other sites

The two registers are at the same offset, just different pages. So, you will need to change the register page to access them both.

Share this post


Link to post
Share on other sites

Yes I can understand that, thats why I tryed changing the page in the first place. The thing that I dont understand is why it makes no difference if I use ADRESL or ADRESH. It would also of helpped if the data sheet had made this point clear.

Terry

Share this post


Link to post
Share on other sites
... thats why I tryed changing the page in the first place.

To the PIC, the two registers are at the exact same address/offset. The paging bits determine which is used.

FWIW, this is a common source of PIC programming confusion. The paging issue affects program code space, ram, and registers. Once you've been bitten by it, it will probably never byte you again. :)

The thing that I dont understand is why it makes no difference if I use ADRESL or ADRESH.

Some higher level languages will manage the paging for you. With assy, it is up to the programmer to mess with these little details.

Share this post


Link to post
Share on other sites

OK, thanks for your answers, I think I have got to grips with the bits I need to write the code now. ;)

Terry

Share this post


Link to post
Share on other sites

oooooops, just deleted a double post.

Terry

Edited by Terry

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×