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.

Led blinking//pic basic

Status
Not open for further replies.

TKS

New Member
Hi hello,

i was wondering wi this prog doesn't work can any one help me:

;Tutorial 1.2 - Nigel Goodwin 2002 :p
LIST p=16F818 ;tell assembler what chip we are using
include "P16F6818.inc" ;include the defaults for the chip
__config 0x3D18 ;sets the configuration settings (oscillator type etc.)

cblock 0x20 ;start of general purpose registers
count1 ;used in delay routine
counta ;used in delay routine
countb ;used in delay routine
endc

org 0x0000 ;org sets the origin, 0x0000 for the 16F628,
;this is where the program starts running


bsf STATUS, RP0 ;select bank 1
movlw b'00000000' ;set PortB all outputs
movwf TRISB
movwf TRISA ;set PortA all outputs
bcf STATUS, RP0 ;select bank 0

Loop
movlw 0xff
movwf PORTA ;set all bits on
movwf PORTB
nop ;the nop's make up the time taken by the goto
nop ;giving a square wave output
call Delay ;this waits for a while!
movlw 0x00
movwf PORTA
movwf PORTB ;set all bits off
call Delay ;3times for being sure it blinks..!!
call Delay
call Delay
goto Loop ;go back and do it again

Delay movlw d'250' ;delay 250 ms (4 MHz clock)
movwf count1
d1 movlw 0xC7
movwf counta
movlw 0x01
movwf countb
Delay_0
decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_0

decfsz count1 ,f
goto d1
retlw 0x00

end


when i program my device succesfully..(picall)

then when i put it in his socket the leds keeps lighting..
and doesn't blink..

TKS
 
There are a couple of obvious mistakes, firstly you've made a mistake in the name of the config file (you left a '6' in it). Secondly you are still using the config setting for the 16F628, you will need to alter it for the 16F818.
 
ok

ok but the assembler accepted it..

exept de 6..i was outside house sow had to made the code again..

would be nice if you could give me the correct settings for the config..

for 8mhz.. internal osci...the rest i don't for example what means mclr pin enabled..???


TKS
 
Re: ok

TKS said:
ok but the assembler accepted it..

exept de 6..i was outside house sow had to made the code again..

would be nice if you could give me the correct settings for the config..

for 8mhz.. internal osci...the rest i don't for example what means mclr pin enabled..???


TKS

Looks like 0x2918 to me - using WinPicProg simply select the options you want, it displays the config value for you. The MCLR pin enabled sets the MCLR pin to act as a reset pin, when it's cleared you can use the MCLR pin as an extra input.
 
internal osc with port IO on oscillator pins.
Watchdog disabled
power on timer enabled
memory clear enabled (needs to be high for program to run)
brown out protection on
low voltage programming disabled (assuming you use a normal HVP programmer)
data eeprom not protected
program flash not write protected
no incircuit debugger

-> config word 0x3F70

-> it's all in the datasheet , section 12
 
i have reallly no idea what it is...

the led just keeps lightning

this is my code..:

;Ld knipper prog
LIST p=16F877 ;tell assembler what chip we are using
include "P16F877.inc" ;include the defaults for the chip
__config 0x3F70 ;sets the configuration settings

cblock 0x20 ;start of general purpose registers
count1 ;used in delay routine
counta ;used in delay routine
countb ;used in delay routine
endc

org 0x0000 ;org sets the origin, 0x0000 for the 16F628,
;this is where the program starts running
;movlw 0x07
;movwf CMCON ;turn comparators off (make it like a 16F84)

bsf STATUS, RP0 ;select bank 1
movlw b'00000000' ;set PortB all outputs
movwf TRISB
movwf TRISA ;set PortA all outputs
bcf STATUS, RP0 ;select bank 0

Loop
movlw 0xff
movwf PORTA ;set all bits on
movwf PORTB
nop ;the nop's make up the time taken by the goto
nop ;giving a square wave output
call Delay ;this waits for a while!
call Delay
call Delay
movlw 0x00
movwf PORTA
movwf PORTB ;set all bits off
call Delay
goto Loop ;go back and do it again

Delay movlw d'255' ;delay 255 ms (4 MHz clock)
movwf count1
d1 movlw 0xC7
movwf counta
movlw 0x01
movwf countb
Delay_0
decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_0

decfsz count1 ,f
goto d1
retlw 0x00

end


hope some on can help

my multi meter says that all pins are high...

i have basicly only 3 wires conected...

1 VDD
1 VSS
and 5volts on the MCLR...

and the led on port RA1

the mclr is conected after a resistor..

1Kohm..

TKS
 
Re: i have reallly no idea what it is...

TKS said:
Ld knipper prog
LIST p=16F877 ;tell assembler what chip we are using
include "P16F877.inc" ;include the defaults for the chip

What chip are you using. The first post it was a 16F818 now its a 'F877?
 
F818

huh...

that's a good one..

i changed it yesterday...

1 moment..

i will look..

it is still 818..

TKS
 
Well for a start, you've changed processors!. You asked about a config word for a 16F818, and then changed to a 16F877 - how do you expect it to work?.

Also, the 18F877 has PortA set as analogue inputs by default, you need to disable them to use PortA as digital I/O. The datasheet explains it, or there are examples in some of my tutorials.

If you connect the LED to PortB (and set the config fuses correctly) it should work.
 
it doesn't make

any difference...

oww what a disillusion that it would be simple..

to flash a led..

for nigel my programmer/chip doesn't accept that config setting..(0x2918)

TKS
 
ok

i now changed it back to F818 the one i'm still trying to put it in work..

hey i'm now seeing that the led flashes but that the time is very high between... lightninh and off..


TKS

i'm gonna inspect the delays from nigel..
 
Re: it doesn't make

TKS said:
any difference...

oww what a disillusion that it would be simple..

to flash a led..

It's very simple, I give tested working code and even veroboard layouts, it's guaranteed to work - but if you change processors you will need to make slight changes, reading the datasheets is paramount!.

for nigel my programmer/chip doesn't accept that config setting..(0x2918)

TKS

For which processor?.
 
think it works...

chip 16F818

after the read it says both are not the same...

now it flashes but i lovered the d value to 10 and deleted both nops

and also 2delays from the 3 in row..

TKS

it keeps still lighting for 3seconds..
 
Re: think it works...

TKS said:
chip 16F818

after the read it says both are not the same...

now it flashes but i lovered the d value to 10 and deleted both nops

and also 2delays from the 3 in row..

TKS

it keeps still lighting for 3seconds..

What value does it read back?.

It sounds like your chip may be running at a slower rate than 4MHz, the 16F818 has 8 different internal oscillator options - check the setting of the OSCCON register.
 
Check **broken link removed** to understand how they work.
Code:
bcf     status,rp0    ;
bsf     status,rp0    ;swich to bank1
movlw   b'0110010'    ;set internal osc to 4 MHz
movwf   osccon        ; 
bcf     status,rp0    ;swich back to bank0

palce this after your __config 0x3FD8 line.

STEVE
 
i was suggesing the manual the data sheet i already have

i think i start whit reading the manual..

what a hell of a difference between visual basic as language and the asm files..

and between the oopic and the pics..


TKS

i was also planning of using some f18 devices.. :lol:
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top