View previous topic :: View next topic |
Author |
Message |
buckeyes1997 Guest
|
programmed chip does nothing |
Posted: Sun Nov 21, 2004 10:34 pm |
|
|
okay so i programmed a simply program that was supposed to set pinb0 high for 100ms and then take it low for 100ms and i get nothing on the scope. i used the wizard to start the project and defined pin b0 as output but i didnt check the box that said to use pullups on portB. it compiled fine and i know the chip is powered and wired correctly as i have gotten a program to work the lcd a little. the program that works was written and compiled with mplab and not ccs.
it seems like even when i compile the program and put it on the chip it doesnt run. if i dont terminate the program it will go back to the top and run the program over and over nonstop right?
what could be wrong.
matt |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sun Nov 21, 2004 10:39 pm |
|
|
Quote: | what could be wrong.
|
All sorts of things. Try posting the code! |
|
|
lucky
Joined: 12 Sep 2003 Posts: 46 Location: South Coast - England
|
programmed chip does nothing |
Posted: Mon Nov 22, 2004 7:01 am |
|
|
Quote: | if i dont terminate the program it will go back to the top and run the program over and over nonstop right? |
The Compiler will add a Sleep(); to the end of your code. Put your code in a loop:
Code: |
while(TRUE){
output_high(PIN_B0);
delay_ms(100);
output_low(PIN_B0);
delay_ms(100);
|
_________________ Lucky
www.mpic3.com - MPIC3 player project, Forum, Downloads, Online Shop |
|
|
buckeyes1997 Guest
|
thanks |
Posted: Mon Nov 22, 2004 9:01 am |
|
|
yes that is exactly the code i used minus the while statement. i thought about adding that but didnt get to it yet. my thought was maybe it is working but stops so quick i never see it on the scope.
ill try that and see. |
|
|
buckeyes1997 Guest
|
i think i need the while statement. |
Posted: Mon Nov 22, 2004 5:24 pm |
|
|
is there a way to strip the sleep statement before writing to the chip???
Code: | #include <ctype.h>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
void main()
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
delay_ms(100);
output_high(PIN_B0);
delay_ms(100);
output_low(PIN_B0);
}
|
|
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Mon Nov 22, 2004 5:40 pm |
|
|
No. You need the while(1); statement. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Nov 22, 2004 6:32 pm |
|
|
To spell it out for you
Code: |
void main()
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
while(1)
{
delay_ms(100);
output_high(PIN_B0);
delay_ms(100);
output_low(PIN_B0);
}
}
|
|
|
|
buckeyes1997 Guest
|
thanks |
Posted: Mon Nov 22, 2004 6:49 pm |
|
|
hey guys ill try that. i thought about using the toggle function but wanted to do it explicitly.
what time delay should i use to make it show up on the scope more clearly?? i think i should easily be able to observe the 100ms on the scope shouldnt i?? i will try it and report my findings.
thanks
matt |
|
|
buckeyes1997 Guest
|
hey it works |
Posted: Tue Nov 23, 2004 6:57 pm |
|
|
hey i was able to verify that the pin toggles on the scope. all i had to do was put the while statement in there to keep it out of sleep. why on earth did they put an invisible sleep command in there. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue Nov 23, 2004 7:33 pm |
|
|
So it would run off into space and then start over. |
|
|
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
Re: hey it works |
Posted: Wed Nov 24, 2004 8:52 am |
|
|
buckeyes1997 wrote: | hey i was able to verify that the pin toggles on the scope. all i had to do was put the while statement in there to keep it out of sleep. why on earth did they put an invisible sleep command in there. |
There is no "operating system" to return to as you would have on a DOS/WINDOWS/UNIX/LINUX box.
Writing C code for a microcontroller is not quite like writing for "big iron" and you are ultimately responsible for providing the microcontroller everything it needs, including how to keep it from falling off the edge of the world when your program ends.
A suggestion, if this is your first time working with a microcontroller, I suggest you try writing a few small, simple programs with MPASM (free from Microchip's web site) and get a feel for that before writing much more C code. You don't have to write a file server or TCP/IP stack in assembly, just blink some leds and maybe try using one of the on-chip perpherials like one of the timers and also debounce a pushbutton switch. Knowing how to do that in assembly will really help you later when you are teasing out a problem in C and need to look at the LST file. _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|
|
|