Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

18F2520 help

Status
Not open for further replies.

Lighty

New Member
Hi All

I'm needing to make LEDs flash (say 1hz) on the RB1 through to RB7, I know it sounds simple bit I only know a bit on GCBasic, but keep running into problem, only if it was as easy as the 16F628:)

any one that can help, I would really appreciate it!
 
The code.

Code:
#chip 18F2520, 4
#config INTRC_OSC & _PWRTE_OFF

#define RB1 PortB.1
#define RB2 PortB.2 
#define RB3 PortB.3
#define RB4 PortB.4
#define RB5 PortB.5
#define RB6 PortB.6
#define RB7 PortB.7

dir RB1 out
dir RB2 out
dir RB3 out
dir RB4 out
dir RB5 out
dir RB6 out
dir RB7 out


Main:
Set RB1 on
Set RB2 on
Set RB3 on
Set RB4 on
Set RB5 on
Set RB6 on
Set RB7 On
Wait 1 s
Set RB1 off
Set RB2 off
Set RB3 off
Set RB4 off
Set RB5 off
Set RB6 off
Set RB7 Off
wait 1 s
goto main
 
You have not told us what the problem is.

Code:
#config INTRC_OSC & _PWRTE_OFF
This is suspect. You did not turn off the watchdog timer WDT (guessing _WDT_OFF) and it looks like bits RB6 and RB7 will be used for debugging. I am not sure what the flag is to use them as IO. It is often INTIO2 or INTIO67 etc.

Code:
#chip 18F2520, 4
This could be OK or maybe not. Does this tell the compiler to setup the internal clock for 4MHz or does it just inform the processor of the clock speed. If it is the second you need to look at the processor data sheet and learn how speed up the clock. The default speed is a few KHz for most processors.
 
You have not told us what the problem is.

Code:
#config INTRC_OSC & _PWRTE_OFF
This is suspect. You did not turn off the watchdog timer WDT (guessing _WDT_OFF) and it looks like bits RB6 and RB7 will be used for debugging. I am not sure what the flag is to use them as IO. It is often INTIO2 or INTIO67 etc.
Indeed, one needs to looks at the config ops for the 18f2520.dat file located in the GCBasic chipdata folder (just like any xxfxxx.inc file). Bonus points for the MPLAB IDE for having that at your fingertips. So use:
Code:
#config Osc=INTIO67
Code:
#chip 18F2520, 4
This could be OK or maybe not. Does this tell the compiler to setup the internal clock for 4MHz or does it just inform the processor of the clock speed. If it is the second you need to look at the processor data sheet and learn how speed up the clock. The default speed is a few KHz for most processors.
Both actually, although when playing with the PLL or a 16mhz internal osc, it always pays to set the OSCON register manually.

The code could be shortened up by just equating PortB to a constant, or a variable, by and'ing it with 0xFE to mask off RB0.
Code:
dir PortB out
...
...
Main:
PortB = b'11111110'
    ;-or-
MyVar = MyVar & 0xFE
PortB = MyVar
wait 1 s
PortB = 0
wait 1 s
goto Main
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top