PDA

View Full Version : can't even flash an LED



bruno333
- 27th April 2005, 20:20
Warning this is an extreme newbie post! I'm just migrating over from Basic Stamps.

Anyway, I'm using PBP with Microchips Pickit USB programmer. 12F675 processor. I'm trying to flash individual LED's on the board with the following very simple program. The strange results are commented below. Anyone have ideas on what I might be doing wrong?

John

' Flash LED (Sample 1)
'
' Blinks LED using HIGH and LOW commands to control specified pin.

CMCON = 7 ' Comparators OFF
ANSEL = 0 ' A/D OFF -- Port pins all digital
TRISIO = %010000 ' All I/O but GPIO3 = outputs
GPIO = %000000 ' All 0 on boot


Symbol LED = 4 ' LED Pin

Loop: High LED ' LED On
Pause 3000 ' Delay 1/2 Second
Low LED ' LED Off
Pause 3000 ' Delay 1/2 Second
goto Loop ' Forever

' LED = 1 flashes D7 on Pickit 1 board
' LED = 4 flashes D2 and D0 on Pickit 1 board
' LED = 5 flashes D4 on Pickit 1 board
' LED = 0 flashes nothing on Pickit 1 board
' LED = 2 flashes D5 and D6 on Pickit 1 board
' LED = 3 flashes nothing on Pickit 1 board

Dwayne
- 27th April 2005, 20:39
Hello John,

JOhn>>
CMCON = 7 ' Comparators OFF
ANSEL = 0 ' A/D OFF -- Port pins all digital
TRISIO = %00001000 ' All I/O but GPIO3 = outputs

I added 2 zeros to your TRISIO, and changed the position of your GPIO.3 switch



Loop:

High GPIO.2

Pause 500

Low GPIO.2

Pause 500

goto Loop

end.


I could not check this out, because I am at work, but this should be very close to what you are looking for.

DWayne

bruno333
- 27th April 2005, 21:03
Thanks for your help. I tried the code below, and it now flashes D2, D4, and D7 on the Pickit 1 board simultaneously. This thing is driving me nuts! Certainly you can symbol a specific output right?


CMCON = 7 ' Comparators OFF
ANSEL = 0 ' A/D OFF -- Port pins all digital
TRISIO = %00001000 ' All I/O but GPIO3 = outputs


Loop: High GPIO.2 ' LED On
Pause 3000 ' Delay 1/2 Second
Low GPIO.2 LED Off
Pause 3000 ' Delay 1/2 Second
goto Loop ' Forever

Dwayne
- 27th April 2005, 21:47
Hello Bruno333,

B>>Certainly you can symbol a specific output right?<<

Yes, you can. But I wanted to give you the simplist of code to start out with.

LEDPin var GPIO.2

Loop:
High LEDPin
pause 500
Low LEDPin
Pause 500
goto Loop
end


Dwayne

Bruce
- 28th April 2005, 05:22
FYI TRIS statements are not necessary when you're using the PBP HIGH & LOW commands. PBP *automatically* sets the pin up as an output.

If you use GPIO.2 = 1 or 0, then you'll need to first set the TRIS register to make this bit an output. If you use HIGH or LOW GPIO.2, then PBP sets GPIO.2 up as an output automatically.

Why the PicKit board gives you odd results is due to the way the LED's are wired on the board. Look for the PicKit board schematic or download it here http://ww1.microchip.com/downloads/en/DeviceDoc/40051D.pdf

Here's a simple BASIC example that strobes LED's D0 to D7 on the PicKit 1 board.


@ DEVICE PIC12F675, INTRC_OSC, WDT_OFF, MCLR_OFF
Define OSCCAL_1K 1 ' Calibrate internal oscillator

CMCON = 7 ' Comparators OFF
ANSEL = 0 ' A/D OFF

' Modified from Microchip PicKit 1 state.asm demo source
D0_D1 CON %00001111 ; TRISIO setting for D0 and D1
D2_D3 CON %00101011 ; TRISIO setting for D2 and D3
D4_D5 CON %00011011 ; TRISIO setting for D4 and D5
D6_D7 CON %00111001 ; TRISIO setting for D6 and D7

'; define LED state (what GPIO will equal)
D0_ON CON %00010000 ; D0 LED
D1_ON CON %00100000 ; D1 LED
D2_ON CON %00010000 ; D2 LED
D3_ON CON %00000100 ; D3 LED
D4_ON CON %00100000 ; D4 LED
D5_ON CON %00000100 ; D5 LED
D6_ON CON %00000100 ; D6 LED
D7_ON CON %00000010 ; D7 LED

TIME VAR BYTE

Main:
FOR TIME = 50 TO 200 STEP 25

TRISIO = D0_D1 : GPIO = D0_ON
PAUSE TIME : GPIO = D1_ON
PAUSE TIME

TRISIO = D2_D3 : GPIO = D2_ON
PAUSE TIME : GPIO = D3_ON
PAUSE TIME

TRISIO = D4_D5 : GPIO = D4_ON
PAUSE TIME : GPIO = D5_ON
PAUSE TIME

TRISIO = D6_D7 : GPIO = D6_ON
PAUSE TIME : GPIO = D7_ON
PAUSE TIME

NEXT TIME
GOTO Main

bruno333
- 28th April 2005, 06:10
Yeah, I just figured out the LED wiring of the Pickit a few minutes ago before I read your post. Very strange way to do things? I've used several development boards, and usually LED's are wired individually to the separate pins so you can quickly (and simply) check program operation. Why on earth did they do it this way? The LED's are wired with several forward and other's reverse polarity. Sure I guess you might want to experiment with Hi and low outputs... but geeze what a mess.

Besides that, it's a nice programmer. No wall-wart, and 36 bucks.

mister_e
- 28th April 2005, 06:27
hehe that's what i often call an engineer trip. Bah that's doing food for your brain cells.

Bruce
- 28th April 2005, 13:27
I think the idea was to show creative appplication of limited resource devices like the 8 & 14-pin targets. It is a nifty board considering the investment.