View previous topic :: View next topic |
Author |
Message |
Steve_Kos
Joined: 06 Sep 2006 Posts: 12
|
PIC12F675 "BLINKY" program |
Posted: Wed Sep 06, 2006 9:33 am |
|
|
Friends,
I am playing with the PIC12F675 for the first time using CCS version 4.005. I am currently just trying to turn on a LED on GP5 using the following:
---------------------------------------------------------------------------------
#include<12F675.h>
#fuses NOWDT, NOPROTECT, PUT, BROWNOUT, NOCPD, INTRC_IO
#device ADC=10
// Standard libraries needed for basic I/O.
#include <stdio.h>
#include <stdlib.h>
// Tell compiler that clock is 4MHz for use in DELAY routines.
#use DELAY(clock=4000000)
// Configure I/O at beginning of routine.
#use standard_io(A)
void main()
{
set_tris_a( 0x1D );
setup_adc( ADC_CLOCK_INTERNAL );
setup_adc_ports( AN0_ANALOG|AN1_ANALOG|AN3_ANALOG );
setup_timer_0( RTCC_INTERNAL|RTCC_DIV_256 );
setup_timer_1( T1_DISABLED );
setup_comparator( NC_NC_NC_NC );
setup_vref(FALSE);
output_a( 0x20 );
#asm
loop:
nop
goto loop
#endasm
}
-------------------------------------------------------------------------------------
Can anybody see anything wrong with this code. As far as I can tell everything looks like it should be working. |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Wed Sep 06, 2006 10:05 am |
|
|
Blink implies that it will turn on,...wait some time,... turn off,..wait some time..loop.
Why use loop nop goto loop
Just put a
while(TRUE);
That means while true is equal to true((which is always)) do the next statement. And the next statement is nothing ((a semicolin))
No need for tris as you are using standard_io.. Tris is taken care of by
the output_n statement.
Note that some port A pins can be "open collector" that is it will pull a line
down and can't pull it high. It needs a pull-up resistor. |
|
|
Ttelmah Guest
|
|
Posted: Wed Sep 06, 2006 10:13 am |
|
|
First, use the 'code' button to post code, and the tick box 'disable HTML in this post', then it has a chance of being readable. Unfortunately without this, parts of the lines get omitted...
What is shown should work, but all it'll do, is turn the line on. No 'blinking'.
Treitmey, has just posted the other things I was going to say.
Best Wishes |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Wed Sep 06, 2006 10:53 am |
|
|
change the pin value to whatever you are using.
Code: | #INCLUDE<12F675>
#USE DELAY(CLOCK=4000000)
#FUSES HS,NOWDT,NOPROTECT
void main()
{
setup_adc_ports(NO_ANALOGS);
set_tris_a(0xFF);//setting all pins to input at startup
while(TRUE){
output_toggle(PIN_A4);//tris is taken care of by output_n function
delay_ms(1000);
}
} |
|
|
|
Steve_Kos
Joined: 06 Sep 2006 Posts: 12
|
PIC12F675 not so "BLINKY" Program |
Posted: Wed Sep 06, 2006 1:41 pm |
|
|
Thanks guys! Program is working as expected now.
It was "growing pains". |
|
|
|