|
|
View previous topic :: View next topic |
Author |
Message |
Arnan Sipitakiat Guest
|
Simple 12F675 LED blinker doesn't work |
Posted: Wed Mar 12, 2003 11:40 pm |
|
|
Okay, I know this is supposed to be real simple but I somehow can not get the 12F675 to work at all. Here's the situation.
- I use CCS 3.148
- Hardware config is simple. Vdd, Vss, and and LED on GP5.
- I know my hardware works. I compiled an ASM code and programmed the PIC in MPLAB. LED is blinking.
- I copied a C code from a few posts in this newsgroup and slightly modified it. None of them work!
So simple so hard!
Please help,
--Roger.
Here's one of the code I used:
///////////////////////////////////////////////////////////
#include <12f675.h>
#fuses INTRC_IO,PUT,NOWDT,NOPROTECT,NOMCLR, BROWNOUT
#use delay(clock=4000000)
//define IO pins
#bit gpio5 =0x05.5
#bit gpio4 =0x05.4
#bit gpio3 =0x05.3
#bit gpio2 =0x05.2
#bit gpio1 =0x05.1
#bit gpio0 =0x05.0
#use fast_io(a)
#byte OSCCAL = 0x90
#byte ADCON0 = 0x1F
#byte ANSEL = 0x9F
#byte CMCON = 0x19
#rom 0x3ff = {0x3470} /// input the calibration code
main()
{
ADCON0 = 0; // ADC off
ANSEL = 0; // GPIO pins 0,1,2 and 4 set to all digital
CMCON = 7; // Comparators off
//setup i/o
set_tris_a(0b001100); //GP0,1,4,5 output; 2,3 input
gpio5=1; gpio4=0; gpio1=0; gpio0=0; //turn on LED on gp5
//set timer0 not to use GP2
setup_counters(rtcc_internal, rtcc_div_2);
while(true)
{
delay_ms(1000);
gpio5=!gpio5; //toggle LEDs just to show program is running
gpio4=!gpio4;
}
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 12604 |
|
|
Michael Grant Guest
|
Re: Simple 12F675 LED blinker doesn't work |
Posted: Thu Mar 13, 2003 5:19 am |
|
|
I have just spent a very frustrating week with a PIC 12F675. From the earlier posts I can see that I am not the only one.
My problem seemed to be that I couldn't flip a GPIO bit without zero-ing every other GPIO bit. I could see it happening on the 'scope - change a bit, the others became zero simultaneously.
My fix is to keep a copy byte in RAM, change bits there by xoring or anding, and write the copy byte to GPIO.
Despite what Microchip says in the book, if a bit in 12f675 port is set to output ( by TRIS) it does not seem to read in the pin when input. I am used to Atmel chips most recently and maybe I forgot something about PICs.
Best of luck, my project is working since I did this. But I also took direct control of the code and did not use the wizard. When time permits I'll investigate further.
Mike G
:=Okay, I know this is supposed to be real simple but I somehow can not get the 12F675 to work at all. Here's the situation.
:=
:=- I use CCS 3.148
:=- Hardware config is simple. Vdd, Vss, and and LED on GP5.
:=- I know my hardware works. I compiled an ASM code and programmed the PIC in MPLAB. LED is blinking.
:=- I copied a C code from a few posts in this newsgroup and slightly modified it. None of them work!
:=
:=So simple so hard!
:=
:=Please help,
:=--Roger.
:=
:=
:=
:=Here's one of the code I used:
:=
:=///////////////////////////////////////////////////////////
:=
:=#include <12f675.h>
:=#fuses INTRC_IO,PUT,NOWDT,NOPROTECT,NOMCLR, BROWNOUT
:=#use delay(clock=4000000)
:=//define IO pins
:=#bit gpio5 =0x05.5
:=#bit gpio4 =0x05.4
:=#bit gpio3 =0x05.3
:=#bit gpio2 =0x05.2
:=#bit gpio1 =0x05.1
:=#bit gpio0 =0x05.0
:=#use fast_io(a)
:=
:=#byte OSCCAL = 0x90
:=
:=#byte ADCON0 = 0x1F
:=#byte ANSEL = 0x9F
:=#byte CMCON = 0x19
:=
:=
:=#rom 0x3ff = {0x3470} /// input the calibration code
:=
:=main()
:={
:=
:=ADCON0 = 0; // ADC off
:=ANSEL = 0; // GPIO pins 0,1,2 and 4 set to all digital
:=CMCON = 7; // Comparators off
:=
:=
:=//setup i/o
:=set_tris_a(0b001100); //GP0,1,4,5 output; 2,3 input
:=gpio5=1; gpio4=0; gpio1=0; gpio0=0; //turn on LED on gp5
:=
:=//set timer0 not to use GP2
:=setup_counters(rtcc_internal, rtcc_div_2);
:=
:=while(true)
:={
:=delay_ms(1000);
:=gpio5=!gpio5; //toggle LEDs just to show program is running
:=gpio4=!gpio4;
:=}
:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 12610 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Simple 12F675 LED blinker doesn't work |
Posted: Thu Mar 13, 2003 4:45 pm |
|
|
:=Okay, I know this is supposed to be real simple but I somehow can not get the 12F675 to work at all. Here's the situation.
:=
:=- I use CCS 3.148
:=- Hardware config is simple. Vdd, Vss, and and LED on GP5.
:=- I know my hardware works. I compiled an ASM code and programmed the PIC in MPLAB. LED is blinking.
:=- I copied a C code from a few posts in this newsgroup and slightly modified it. None of them work!
-------------------------------------------------------
If you compiled an ASM program, and it works, then you
should be able to compare it to the .LST file created by
the compiler, and find the differences.
If that doesn't work for you, or no one else responds,
I can take a 12F629 (similar chip) and make a test program
and test it on the actual chip. But I'll have to do it
later in the day.
___________________________
This message was ported from CCS's old forum
Original Post ID: 12643 |
|
|
Arnan Sipitakiat Guest
|
Re: Simple 12F675 LED blinker doesn't work |
Posted: Thu Mar 13, 2003 4:51 pm |
|
|
:=:=Okay, I know this is supposed to be real simple but I somehow can not get the 12F675 to work at all. Here's the situation.
:=:=
:=:=- I use CCS 3.148
:=:=- Hardware config is simple. Vdd, Vss, and and LED on GP5.
:=:=- I know my hardware works. I compiled an ASM code and programmed the PIC in MPLAB. LED is blinking.
:=:=- I copied a C code from a few posts in this newsgroup and slightly modified it. None of them work!
:=-------------------------------------------------------
:=
:=If you compiled an ASM program, and it works, then you
:=should be able to compare it to the .LST file created by
:=the compiler, and find the differences.
:=
I tried comparing the ASM but their structures are quite different. I even tried to copy some lines to my C program. No hope so far.
:=If that doesn't work for you, or no one else responds,
:=I can take a 12F629 (similar chip) and make a test program
:=and test it on the actual chip. But I'll have to do it
:=later in the day.
This would be greatly appreciated!
--Roger.
___________________________
This message was ported from CCS's old forum
Original Post ID: 12646 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Simple 12F675 LED blinker doesn't work |
Posted: Thu Mar 13, 2003 8:26 pm |
|
|
I tested the following program with PCM vs. 3.148 and
a 12F629, and it worked OK. I installed LEDs on pins 2 and 3
and they blinked sequentially. This is essentially the same
program you posted.
I had to upgrade to MPLAB 6.13, and also upgrade my PicStart+
to vs. 3.11 to do this. (I haven't used this PIC before).
I assume you're doing this already, but I'll mention it anyway:
1. The LEDs are connected with the anode going to the PIC
i/o pins (pins 2 and 3 for this test).
The cathode has a 330 ohm series resistor connected to it,
and the other end of the resistor goes to ground.
2. Pin 1 of the PIC is +5v and Pin 8 is Ground.
Code: | #include <12F629.h>
#fuses INTRC_IO,PUT,NOWDT,NOPROTECT,NOMCLR, BROWNOUT
#use delay(clock = 4000000)
//define IO pins
#bit gpio5 =0x05.5
#bit gpio4 =0x05.4
#bit gpio3 =0x05.3
#bit gpio2 =0x05.2
#bit gpio1 =0x05.1
#bit gpio0 =0x05.0
#use fast_io(a)
#byte OSCCAL = 0x90
#byte ADCON0 = 0x1F
#byte ANSEL = 0x9F
#byte CMCON = 0x19
// We don't need this line, because MPLAB 6.13 is smart
// enough to know the calibration memory is already programmed.
// (I hope so anyway. At least, it reports this is so).
// #rom 0x3ff = {0x34B4} // Calibration code read from chip
main()
{
ADCON0 = 0; // ADC off
ANSEL = 0; // GPIO pins 0,1,2 and 4 set to all digital
CMCON = 7; // Comparators off
// Setup i/o
set_tris_a(0b001100); //GP0,1,4,5 output; 2,3 input
gpio5 = 1;
gpio4 = 0;
gpio1 = 0;
gpio0 = 0; //turn on LED on gp5
// Set timer0 not to use GP2
setup_counters(rtcc_internal, rtcc_div_2);
while(true)
{
delay_ms(1000);
gpio5 = !gpio5; //toggle LEDs just to show program is running
gpio4 = !gpio4;
}
} |
___________________________
This message was ported from CCS's old forum
Original Post ID: 12653
-----------
Edited on 4-21-2004 to remove unnecessary html tags, and to
put the source code within a "code" block for the new forum.
Last edited by PCM programmer on Wed Apr 21, 2004 4:33 pm; edited 1 time in total |
|
|
Robert Holmer Guest
|
Re: Simple 12F675 LED blinker doesn't work |
Posted: Fri Mar 14, 2003 3:32 am |
|
|
When fast_io is used one must be careful not to have two outputs directly after each other (if clock speed is "fast" enough) since an output means the PIC also does an input which means that the input can read a wrong value from the just changed output (since it is not stable). This can happen even if a only single bit is changed since the PIC reads/write the entire port. As a test, try to put a short delay, delay_cycled(5) for example between
Withe the code below:
while(true)
{
delay_ms(1000);
gpio5=!gpio5; //toggle LEDs just to show program is running
delay_cycles(5);
gpio4=!gpio4;
}
}
Give it a try anyway - it could be this.
Good luck,
Rob
:=I have just spent a very frustrating week with a PIC 12F675. From the earlier posts I can see that I am not the only one.
:=
:=My problem seemed to be that I couldn't flip a GPIO bit without zero-ing every other GPIO bit. I could see it happening on the 'scope - change a bit, the others became zero simultaneously.
:=
:=My fix is to keep a copy byte in RAM, change bits there by xoring or anding, and write the copy byte to GPIO.
:=
:=Despite what Microchip says in the book, if a bit in 12f675 port is set to output ( by TRIS) it does not seem to read in the pin when input. I am used to Atmel chips most recently and maybe I forgot something about PICs.
:=Best of luck, my project is working since I did this. But I also took direct control of the code and did not use the wizard. When time permits I'll investigate further.
:=Mike G
:=
:=
:=:=Okay, I know this is supposed to be real simple but I somehow can not get the 12F675 to work at all. Here's the situation.
:=:=
:=:=- I use CCS 3.148
:=:=- Hardware config is simple. Vdd, Vss, and and LED on GP5.
:=:=- I know my hardware works. I compiled an ASM code and programmed the PIC in MPLAB. LED is blinking.
:=:=- I copied a C code from a few posts in this newsgroup and slightly modified it. None of them work!
:=:=
:=:=So simple so hard!
:=:=
:=:=Please help,
:=:=--Roger.
:=:=
:=:=
:=:=
:=:=Here's one of the code I used:
:=:=
:=:=///////////////////////////////////////////////////////////
:=:=
:=:=#include <12f675.h>
:=:=#fuses INTRC_IO,PUT,NOWDT,NOPROTECT,NOMCLR, BROWNOUT
:=:=#use delay(clock=4000000)
:=:=//define IO pins
:=:=#bit gpio5 =0x05.5
:=:=#bit gpio4 =0x05.4
:=:=#bit gpio3 =0x05.3
:=:=#bit gpio2 =0x05.2
:=:=#bit gpio1 =0x05.1
:=:=#bit gpio0 =0x05.0
:=:=#use fast_io(a)
:=:=
:=:=#byte OSCCAL = 0x90
:=:=
:=:=#byte ADCON0 = 0x1F
:=:=#byte ANSEL = 0x9F
:=:=#byte CMCON = 0x19
:=:=
:=:=
:=:=#rom 0x3ff = {0x3470} /// input the calibration code
:=:=
:=:=main()
:=:={
:=:=
:=:=ADCON0 = 0; // ADC off
:=:=ANSEL = 0; // GPIO pins 0,1,2 and 4 set to all digital
:=:=CMCON = 7; // Comparators off
:=:=
:=:=
:=:=//setup i/o
:=:=set_tris_a(0b001100); //GP0,1,4,5 output; 2,3 input
:=:=gpio5=1; gpio4=0; gpio1=0; gpio0=0; //turn on LED on gp5
:=:=
:=:=//set timer0 not to use GP2
:=:=setup_counters(rtcc_internal, rtcc_div_2);
:=:=
:=:=while(true)
:=:={
:=:=delay_ms(1000);
:=:=gpio5=!gpio5; //toggle LEDs just to show program is running
:=:=gpio4=!gpio4;
:=:=}
:=:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 12663 |
|
|
|
|
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
|