Jump to content

Recommended Posts

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);
}
}

Link to post
Share on other sites
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

Link to post
Share on other sites

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!

Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...