|
|
View previous topic :: View next topic |
Author |
Message |
roman1982 Guest
|
pic18f not entering code |
Posted: Mon Dec 14, 2009 10:40 pm |
|
|
Hi
My program is not entering the "FUNCTIONS" code (18F252 & 18F4520). It happened in the last week when I try to begin with 18F4550.
The programs written before (18F252 & 18F4520), entering the "FUNCTIONS" code. Entering interrupts. I suppose I am missing something.
I am using the CCS Wizard for the programs, MPLAB simulator and a board. The old programs all works in MPLAB and the board. The new, don't.
I have reinstalled the CCS compiler (3.249) and the plugins. No change.
Have restored the system (Windows) to 3 weeks ago.
The new code below:
Code: |
#include "252.h"
//#include "252VAR.h"
//#include "252FUNCTIONS.h"
int timer20ms=0;
short ledflag=1;
void FUNCTIONS_isr(void)
{
restart_wdt();
if (timer20ms==25)
{
timer20ms=0;
if (ledflag==0)
{
output_low(PIN_A4);
ledflag=1;
}
else
{
output_high(PIN_A4);
ledflag=0;
}
}
//aditonal functions
}
#int_TIMER0
void TIMER0_isr(void)
{
restart_wdt();
set_timer0(45536);//to interrupt after 20ms
timer20ms++;
}
#int_RDA
void RDA_isr(void)
{
//serial rx
}
#int_TBE
void TBE_isr(void)
{
//serial tx
}
void main(void)
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_wdt(WDT_ON);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
enable_interrupts(INT_TIMER0);
enable_interrupts(INT_RDA);
enable_interrupts(INT_TBE);
setup_oscillator(False);
enable_interrupts(GLOBAL);
while(1)
{
restart_wdt();
enable_interrupts(GLOBAL);
FUNCTIONS_isr ();
}
}
|
Code: |
#include <18F252.h>
#device adc=8
#FUSES WDT8 //Watch Dog Timer uses 1:8 Postscale
#FUSES H4 //High speed osc with HW enabled 4X PLL
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOOSCSEN //Oscillator switching is disabled, main oscillator is source
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV42 //Brownout reset at 4.2V
#FUSES PUT //Power Up Timer
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOCPD //No EE protection
#FUSES NOCPB //No Boot Block code protection
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#use delay(clock=32000000,RESTART_WDT)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,restart_wdt)
|
Please help
Roman |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 14, 2009 10:52 pm |
|
|
Quote: |
#int_RDA
void RDA_isr(void)
{
//serial rx
}
#int_TBE
void TBE_isr(void)
{
//serial tx
}
enable_interrupts(INT_RDA);
enable_interrupts(INT_TBE);
|
Comment out these last two lines. You don't have any code in the
#int_rda isr to get the character. Therefore, the PIC will constantly be
executing the #int_rda isr. Also, the UART transmitter will always be
empty in your program, and therefore you will get continuous int_tbe
interrupts. Don't enable interrupts if you don't have code to handle
the clearing of the interrupt (where required by the peripheral module).
Delete this line. You don't need it. The SPI module is already disabled
on power-up anyway.
Quote: |
#FUSES WDT8
setup_wdt(WDT_ON);
|
Don't enable the Watchdog timer in a test program that is testing
something else, such as the FUNCTIONS_isr routine. The Watchdog
will just add confusion to the testing. Only test one problem at a time.
Quote: | output_high(PIN_A4); |
This pin has an open-drain driver. To make it work with an LED, you
would need to connect the Cathode of the LED to the pin. Then connect
the anode to a 470 ohm series resistor, and then connect the other side
of the resistor to +5v. |
|
|
roman1982 Guest
|
not entering code |
Posted: Tue Dec 15, 2009 2:39 am |
|
|
PCM programmer
Thank you for the advises
It works perfect after correcting according to your remarks
Roman |
|
|
|
|
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
|