|
|
View previous topic :: View next topic |
Author |
Message |
john bougs
Joined: 11 Feb 2005 Posts: 6
|
can't get 10f206 to do any thing....argh |
Posted: Fri Feb 11, 2005 3:01 pm |
|
|
I cant seem to get any code to run on a 10f206
Version of your compiler: 3.217
Target PIC Microcontroller PIC10F206 @ 5V
I have given up on my code and tried the EX_TGETC.C example. the only lines I have changed are
Code: | #if defined(__PCB__)
#include <10f206.h>
#fuses NOMCLR, NOWDT,NOPROTECT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_B0, rcv=PIN_B1) |
but the processor will not run. I have verified the the device is programming. (an read back / verify the code) any ideas what i am doing wrong?
Code: | /////////////////////////////////////////////////////////////////////////
//// EX_TGETC.C ////
//// ////
//// This program echoes the key presses of the user and times- ////
//// out after a specified amount of time. ////
//// ////
//// Configure the CCS prototype card as described below. ////
//// ////
//// This example will work with the PCB, PCM and PCH compilers. ////
//// The following conditional compilation lines are used to ////
//// include a valid device for each compiler. Change the device, ////
//// clock and RS232 pins for your hardware if needed. ////
/////////////////////////////////////////////////////////////////////////
//// (C) Copyright 1996,2003 Custom Computer Services ////
//// This source code may only be used by licensed users of the CCS ////
//// C compiler. This source code may only be distributed to other ////
//// licensed users of the CCS C compiler. No other use, ////
//// reproduction or distribution is permitted without written ////
//// permission. Derivative programs created using this software ////
//// in object code form are not restricted in any way. ////
/////////////////////////////////////////////////////////////////////////
#if defined(__PCB__)
#include <10f206.h>
#fuses NOMCLR, NOWDT,NOPROTECT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_B0, rcv=PIN_B1)
#elif defined(__PCM__)
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // Jumpers: 8 to 11, 7 to 12
#elif defined(__PCH__)
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // Jumpers: 8 to 11, 7 to 12
#endif
#include <input.c>
#define KEYHIT_DELAY 500 // in milliseconds
char timed_getc() {
long timeout;
char retval;
timeout=0;
while(!kbhit() && (++timeout< (KEYHIT_DELAY*100)))
delay_us(10);
if(kbhit())
retval = getc();
else
retval = 0;
return(retval);
}
void main()
{
int status;
char value;
while(TRUE)
{
status=1;
printf("\r\nStart typing:\r\n");
while(!kbhit());
while(status==1)
{
value=timed_getc();
if(value==0)
status=0;
else
{
status=1;
putc(value);
}
}
printf("\r\nToo slow!\r\n");
}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Feb 11, 2005 5:26 pm |
|
|
The comparator in the 10F206 is turned on by default, at power-up.
CCS may not turn it off in their startup code. I don't have
the PCW compiler, so I can't test that for you.
If they don't turn it off, the next step would be to use the CCS
setup_comparator() function to do that. Example:
setup_comparator(NC_NC_NC_NC);
You may want to check the 10F206.H file, and see if NC_NC_NC_NC is
the proper constant that CCS uses to turn off the comparator for
the 10F206.
If that function doesn't work, then you can do it manually with code
by defining the address of the CMCON0 register, and then writing
the appropriate value to it. Example:
Code: |
#include <10F206.h>
#fuses NOMCLR, NOWDT,NOPROTECT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_B0, rcv=PIN_B1)
#byte CMCON0 = 0x07 // Define the address of CMCON0
void main()
{
CMCON0 = 0xF7; // Turn off the comparator (Set CMPON = 0)
printf("Hello World");
while(1); // Prevent PIC from going to sleep
}
|
|
|
|
theMagni
Joined: 21 May 2004 Posts: 48 Location: Victoria, BC
|
Two things |
Posted: Fri Feb 11, 2005 5:59 pm |
|
|
There are two issues using the 10F series with CCS. First, you'll have to use a touch of assembly to get the tristates to work correctly. I wasn't able to set the tristating any other way, despite the documentation.
Use this:
Code: |
//set the tristating for the IO port.
//TRIS is not a physical register, so it must be set using TRIS.
#asm
//Set the GP pins.
//GP0 is X; input
//GP1 is Y; input
//GP2 is Z; output
//GP3 is A; input. (The pin is input only)
movlw 0b00000000
movwf GPIO
movlw 0b11111011
tris GPIO
#endasm
|
Second, if you're using quickwriter, you'll have to fight it tooth and nail to keep the MRCLR fuse disabled. If you've got input on that pin, it might just reset the pic instead of doing what you expect.
Reviewing your code, it looks like you have a few extra #use rs232 and include files in there that you should get rid of. Also, with the #use delay set at 20MHz, the 4MHz clock isn't going to sync right. _________________ In the 90's, I promised myself I'd never use a so-called "smiley icon". I hate what I've become. ;) |
|
|
john bougs
Joined: 11 Feb 2005 Posts: 6
|
|
Posted: Mon Feb 14, 2005 3:33 pm |
|
|
Thanks the comparator was the problem. Things are happy now. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|