View previous topic :: View next topic |
Author |
Message |
SveinR
Joined: 04 Aug 2005 Posts: 9
|
10F202 I/O problem |
Posted: Thu Aug 04, 2005 3:39 pm |
|
|
Hi!
I'm just playing around with the !0F202, and I cant get det GP2(B2) pin to act as an output, only as an input.. I have made an silly easy code to only blink with some leds to test this..
"
#include "10F202.H"
//#fuses NOBROWNOUT,NOMCLR,NOWDT,NOPROTECT,NOPUT
// Skal benytte 4MHz kystall.
#use delay (clock=4000000)
PORT_B_PULLUPS(TRUE);
void main(void) {
while (TRUE) {
// BLITZ BL� LYS
output_bit( PIN_b0, 1);
output_bit( PIN_b1, 0);
output_bit( PIN_b2, 1);
delay_ms (50);
output_bit( PIN_b0, 0);
output_bit( PIN_b1, 1);
output_bit( PIN_b2, 1);
delay_ms (50);
}
}//Slutt main()
"
Using CCS v 3.212
Regards
Svein |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 04, 2005 8:16 pm |
|
|
I don't have the PCB compiler, so I can't check the ASM code,
but it's possible that CCS doesn't initialize the OPTION register
properly. Upon power-up reset, the OPTION register is initialized
to all 1's. This will make GP2 into an input. It overrides the
normal TRIS.
To fix this problem, you need to set the T0CS bit in the OPTION
register = 0. This requires ASM code. CCS has a macro for this,
as shown below.
Try adding the following code to your program and see if it works.
I've also set it to enable the pullups, because you showed that
you wanted to do that in your post.
Code: |
#define set_options(value) {#ASM \
MOVLW value \
OPTION \
#ENDASM}
//==============================
void main()
{
// Enable GP2 for i/o, and enable weak pullups.
set_options(0b10011111);
while(1);
} |
|
|
|
SveinR
Joined: 04 Aug 2005 Posts: 9
|
|
Posted: Fri Aug 05, 2005 5:25 am |
|
|
Okey!! I will try this when I get home from work. THANKS
But in that TRIS register, do it control the other pins? And do you set the GP0 an GP1 also as output??
Why wont the SET_TRIS_B comand work?
Regards |
|
|
SveinR
Joined: 04 Aug 2005 Posts: 9
|
|
Posted: Sat Aug 06, 2005 5:06 am |
|
|
It works!!! THANKS A LOT |
|
|
|