Terry 5 Report post Posted October 28, 2006 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 Quote Share this post Link to post Share on other sites
Mr.RC-Cam 126 Report post Posted October 30, 2006 Have you looked through the app notes at the microchip site? They should have generic PIC16F A/D code there. Quote Share this post Link to post Share on other sites
Terry 5 Report post Posted October 30, 2006 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 Quote Share this post Link to post Share on other sites
Kilrah 2 Report post Posted October 30, 2006 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. Quote Share this post Link to post Share on other sites
Terry 5 Report post Posted October 30, 2006 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 Quote Share this post Link to post Share on other sites
Kilrah 2 Report post Posted October 30, 2006 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 Are you sure your PIC isn't running? Quote Share this post Link to post Share on other sites
Terry 5 Report post Posted October 30, 2006 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 Quote Share this post Link to post Share on other sites
Terry 5 Report post Posted October 30, 2006 For some reason its not using the internal oscillator, what config word should I be using ? Terry Quote Share this post Link to post Share on other sites
Kilrah 2 Report post Posted October 30, 2006 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 Quote Share this post Link to post Share on other sites
Terry 5 Report post Posted October 30, 2006 I just mean change the config line from XT to INTRC_IO but for some reason its not working. Terry Quote Share this post Link to post Share on other sites
Kilrah 2 Report post Posted October 30, 2006 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... Quote Share this post Link to post Share on other sites
Terry 5 Report post Posted October 30, 2006 Take a look, it has to be something silly 16f818_test2.txt Quote Share this post Link to post Share on other sites
Terry 5 Report post Posted October 30, 2006 ooops seems the site has scrambled it ! Quote Share this post Link to post Share on other sites
Terry 5 Report post Posted October 30, 2006 Try This Quote Share this post Link to post Share on other sites
Kilrah 2 Report post Posted October 30, 2006 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 Quote Share this post Link to post Share on other sites
Terry 5 Report post Posted October 30, 2006 Yep tryed 2 chips and without the wait lines. Im thinking it maybe my programmer. Terry Quote Share this post Link to post Share on other sites
Terry 5 Report post Posted October 30, 2006 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 Quote Share this post Link to post Share on other sites
Kilrah 2 Report post Posted October 30, 2006 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? Quote Share this post Link to post Share on other sites
Terry 5 Report post Posted October 30, 2006 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 Quote Share this post Link to post Share on other sites
Terry 5 Report post Posted November 1, 2006 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 Quote Share this post Link to post Share on other sites
Mr.RC-Cam 126 Report post Posted November 1, 2006 The two registers are at the same offset, just different pages. So, you will need to change the register page to access them both. Quote Share this post Link to post Share on other sites
Terry 5 Report post Posted November 1, 2006 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 Quote Share this post Link to post Share on other sites
Mr.RC-Cam 126 Report post Posted November 1, 2006 ... 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. Quote Share this post Link to post Share on other sites
Terry 5 Report post Posted November 2, 2006 OK, thanks for your answers, I think I have got to grips with the bits I need to write the code now. Terry Quote Share this post Link to post Share on other sites
Terry 5 Report post Posted November 2, 2006 (edited) oooooops, just deleted a double post. Terry Edited November 2, 2006 by Terry Quote Share this post Link to post Share on other sites