JB99 0 Posted April 19, 2010 Report Share Posted April 19, 2010 Hello all, I'm evaluating the C compiler to see if it will be suitable for a small project I want to do so first of all thank you producing it Now my problem, I have a pickit2 and the low pin count board that comes with it. It has a 16F690 chip and LEDs on portc bits 0-3 and a switch on porta bit 3 As a simple test I've made the following program. All if is supposed to do is to flash one LED and have the other reflect the state of the input bit. However it only displays the state of the input bit. If I swap around the two lines that set the port bits then it only flashes. It's as if the first assignment to a bit of port C doesn't work. The point is that both the LED setting lines work individually but when I have them both one doesn't do anything. The board is working fine as the assembly language version works ok. Basically this is my first C program for this board and I'm wondering if I missed something somewhere... #include <system.h> #pragma DATA _CONFIG, _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_OFF & _WDT_OFF & _INTOSCIO #pragma CLOCK_FREQ 4000000 int main() { trisc = 0x00; trisa = 0x08; char d = 0; while(1) { portc.0 = d; /* Set first LED to flash */ portc.1 = porta.3; /* Second LED on button state */ d = !d; delay_ms(200); } } Quote Link to post Share on other sites
davidb 0 Posted April 19, 2010 Report Share Posted April 19, 2010 Hello all, I'm evaluating the C compiler to see if it will be suitable for a small project I want to do so first of all thank you producing it Now my problem, I have a pickit2 and the low pin count board that comes with it. It has a 16F690 chip and LEDs on portc bits 0-3 and a switch on porta bit 3 As a simple test I've made the following program. All if is supposed to do is to flash one LED and have the other reflect the state of the input bit. However it only displays the state of the input bit. If I swap around the two lines that set the port bits then it only flashes. It's as if the first assignment to a bit of port C doesn't work. The point is that both the LED setting lines work individually but when I have them both one doesn't do anything. The board is working fine as the assembly language version works ok. Basically this is my first C program for this board and I'm wondering if I missed something somewhere... Could be the classic read-modify-write problem when writing individual bits to the port registers. Easily solved by using shadow registers. Look this up in the datasheet or find a good description (and ready made solution) by Ian Harris at: http://embeddedadventures.blogspot.com/200...s-and-sfrs.html. Regards davidb Quote Link to post Share on other sites
JB99 0 Posted April 19, 2010 Author Report Share Posted April 19, 2010 Ah, yes that's it. I even avoided that problem in my assembly language version and completely forgot about it in the C version. It works properly now. Thank you and sorry for such a trivial problem! Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.