View previous topic :: View next topic |
Author |
Message |
jt06
Joined: 01 Nov 2007 Posts: 6
|
Does anyone could help me? (Beginner in 18F family) |
Posted: Thu Nov 01, 2007 2:57 am |
|
|
Hi,
Absolute beginner in programming the family PIC 18F.
For starting, I try to have 2 alternatives blinkings LED (one on port A.0 and the second on Port E.0).
This code tested on a 16F877a is OK.
I am not able to migrate this simplest code on a 18F4620 (or a 18F4550)!!!
I think that the problem is in fuse configuration?
Does anyone could help me?
Below the fabulous code:
Many thank's in advance for your help.
Regards,
Jo
Quote: | #include <18F4620.H>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=20000000)
#byte portA=0x80 // Port A Address
#byte portE=0x84 // Port E Address
#bit oLed0 = PortA.0
#bit oLed1 = PortE.0
void main()
{
delay_ms(15);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
SET_TRIS_A(0x00); // Port A Output
SET_TRIS_E(0x00); // Port E Output
while(1)
{
oLed0 = 0; // LED 0 ON
oLed1 = 1; // LED 1 OFF
delay_ms(500);
oLed0 = 1; // LED 0 OFF
oLed1 = 0; // LED 1 ON
delay_ms(500);
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Nov 01, 2007 3:04 am |
|
|
Quote: | #byte portA=0x80 // Port A Address
#byte portE=0x84 // Port E Address |
Look in the PIC data sheet in this section:
Quote: | TABLE 5-1: SPECIAL FUNCTION REGISTER MAP |
Compare the Port addresses above, to the addresses in the data sheet. |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Thu Nov 01, 2007 8:33 am |
|
|
Quote: |
Absolute beginner in programming the family PIC 18F.
|
If you are a beginner in programing MCU, it is a good practice to read and understand
the manufacturer info published in Datasheets. Are you aware that there is a big
difference between both MCU? Hence it is improbable that the code that was running
in the 16F would run in the 18F. The PIC18F4620 has a complex architecture
compared with the 16F.
It is a good practice to shut down the modules that is not in use.
Most of this is done by the Compiler in background, but as a programmer you are the
responsible of the generated code, not the tools that you are using.
I suggest you to be explicit while coding, do not assume that somebody will do it for you.
Following is an example of what I mean.
Code: |
#include <18F4620.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPROTECT //Code not protected from reading
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV28 //Brownout reset at 2.8V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES XINST //Extended set extension and Indexed Addressing mode enabled
#FUSES PBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES MCLR //Master Clear pin enabled
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF|ADC_TAD_MUL_0);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
output_high(PIN_A0);
output_low(PIN_E0);
while(1)
{
output_toggle(PIN_A0);
output_toggle(PIN_E0);
delay_ms(500);
}
}
|
Humberto |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Thu Nov 01, 2007 9:56 am |
|
|
Plus one thing to know, the set_tris command is useless unless fast_io is stated. At least that's what the help file states. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Thu Nov 01, 2007 11:38 am |
|
|
rnielsen wrote: | Plus one thing to know, the set_tris command is useless unless fast_io is stated. At least that's what the help file states. |
I would say the set_tris command is UNNECESSARY unless you are using fast_io. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
jt06
Joined: 01 Nov 2007 Posts: 6
|
|
Posted: Sat Nov 03, 2007 1:00 am |
|
|
PCM programmer wrote: | Quote: | #byte portA=0x80 // Port A Address
#byte portE=0x84 // Port E Address |
Look in the PIC data sheet in this section:
Quote: | TABLE 5-1: SPECIAL FUNCTION REGISTER MAP |
Compare the Port addresses above, to the addresses in the data sheet. |
Many thank's for that.
Regards |
|
|
jt06
Joined: 01 Nov 2007 Posts: 6
|
|
Posted: Sat Nov 03, 2007 2:20 am |
|
|
Thanks to everyone |
|
|
|