PDA

View Full Version : don't work on circuit, please help



DonLuis
- 24th July 2012, 13:50
Hi you all:
I am from mexico, and I do apologize for my English, so I am new to programming, as a matter of fact this is my first intent, I have learned reading from posts on this forum and consulting the pbp and proteus manuals, the thing is that I wrote this code on pbp 2.6 and simulated it on proteus and works fine so i programmed the micro controller with masterprog (wich is a programmer that I got from Mercado libre, same than ebay over there) and when I put the micro on the protoboard nothing happened, and when I pressed the reset button and tree leds light up (00101010) and stay on and nothing else, I have tried reprogramming and checked al connections over and over again but noting seems to work, I have read many threads on this forum but I don’t find anything that can help, so I really will appreciate if any one look at the code and comment what I am doing wrong thanks very much in advance.
This is the code

'Note: This program it will light eight leds on nine different routines selectables by a button
@ DEVICE PIC16F877A, HS_OSC
@ DEVICE PIC16F877A, WDT_OFF
@ DEVICE PIC16F877A, PWRT_OFF
@ DEVICE PIC16F877A, BOD_OFF
@ DEVICE PIC16F877A, LVP_OFF
@ DEVICE PIC16F877A, CPD_OFF
@ DEVICE PIC16F877A, WRT_HALF
@ DEVICE PIC16F877A, DEBUG_ON
@ DEVICE PIC16F877A, PROTECT_OFF

tempo var byte ' set variables
cuenta var byte
x var byte
bot var byte

tempo= 50 ' set variables values
bot= 0

trisa= 0 ' set port's tris
trisb= 0
trisc= %00100000
trisd= 0
trise= 0

inicio: ' begining of routines
portb= %10101010 ' this loop makes odd and pair
pause tempo ' leds to turn on and off alternately
portb= %01010101
pause tempo
button portc.2,0,100,0,bot,1,una
goto inicio

una:
portb=%11111111 ' this loop makes all leds to turn
pause tempo ' on and off alternately
portb= %00000000
pause tempo
button portc.2,0,100,0,bot,1,dos
goto una

dos: ' this loop makes the leds to scroll
portb=%00011000 ' from the center outwards
pause tempo
portb= %00100100
pause tempo
portb= %01000010
pause tempo
portb= %10000001
pause tempo
button portc.2,0,100,0,bot,1,tres
goto dos

tres: ' this loop makes the leds scroll from the
portb=%10000001 ' sides inwards
pause tempo
portb= %01000010
pause tempo
portb= %00100100
pause tempo
portb= %00011000
pause tempo
button portc.2,0,100,0,bot,1,cuatro
goto tres

cuatro:
portb=%00001111 ' this loop makes leds to turn on and off four
pause tempo ' at the time
portb= %11110000
pause tempo
button portc.2,0,100,0,bot,1,cinco
goto cuatro

cinco:
cuenta=1 ' this loop makes leds to scrool from right
ciclo: ' to left
portb=cuenta
pause tempo
if cuenta= 128 then cinco
cuenta= cuenta*2
button portc.2,0,100,0,bot,1,seis
goto ciclo

seis:
cuenta=128 ' this loop makes leds to scroll from left
ultimo: ' to right
portb=cuenta
pause tempo
if cuenta= 0 then seis
cuenta= cuenta/2
button portc.2,0,100,0,bot,1,siete
goto ultimo

siete:
portb= %11000000 ' this loop makes leds to scroll on pairs from
pause tempo ' left to right
portb= %00110000
pause tempo
portb= %00001100
pause tempo
portb= %00000011
pause tempo
button portc.2,0,100,0,bot,1,ocho
goto siete

ocho:
portb= %00000011 ' this loop makes leds to scroll on pairs from
pause tempo ' right to left
portb= %00001100
pause tempo
portb= %00110000
pause tempo
portb= %11000000
pause tempo
button portc.2,0,100,0,bot,1,inicio
goto ocho

end

and this is the schematic from proteus

6607

ScaleRobotics
- 24th July 2012, 14:50
Hi, and welcome to the forum DonLuis.

Proteus lets a lot of things work in the virtual world, that will not work in the real world. For the real world 16F877 you need an oscillator to be connected, or a resonator. Resonators already have the capacitors needed, but aren't quite as accurate as real crystals. If you get a 8 to 16 mhz crystal, you will need two 10 to 20 pf capacitors. See page 145 of the datasheet (147 in adobe).

grahamg
- 24th July 2012, 17:59
Trisc should be = %00000100

DonLuis
- 25th July 2012, 03:00
Thank you grahamg and scalerobotics for answering.

I already corrected the trisc issue and I do have installed the xtal, I have tried with a 4 and 18 Mhz before and the problem remains still, I wonder if the fuses are correct or I am missing something , I also thing that something is wrong with the programmer but I’ll like to make sure before I contact the seller, or the pic is to big for the program what do you tink.

Demon
- 25th July 2012, 03:36
Increase the PAUSE in TEMPO, 500 would be a good start.

Robert

ScaleRobotics
- 25th July 2012, 04:32
4 mhz would require the config to be XT_OSC. I would try changing to the XT config using the 4 mhz chip. Oh, that and turn debugger off. Otherwise you can't use RB6 and RB7.

DonLuis
- 26th July 2012, 02:30
Ok. Guys:
I do have good and bad news, I teared the hole thing apart and stared from the beginning (the circuit I mean) and changed the XT and turned the debug off and ˇooorale! It works, that is the good one, the bad one is that I don’t really know what happened, any way thank you all very, very much. ahh and changed tempo to 500 also

AvionicsMaster1
- 26th July 2012, 14:46
Well, you say you're new to programming so why not take a step back and write a few routines to make sure you're LEDs are working properly and connected well?

Your schematic isn't very clear on my screen but it looks like your LEDs are hooked to PORTB. Something like:
(I usually work with 12F683 so this code may not be totally correct.)

STARTHERE:
TRISB = 0
PORTB = 0
PORTB = %00000001
PAUSE 100
PORTB = %00000010
PAUSE 100
PORTB = %00000100
PAUSE 100
BLAH BLAH BLAH


GOTO STARTHERE

This way you know the LEDs will work once you get the right code.

Also, I see it worked in Proteus but if the real world LEDs need more voltage/current, looks like a 330ohm current limiting resistor, than 6mA the LEDs may never come on no matter what your programming looks like.

Could you post an updated schematic if none of this helps? Sometimes a second set of eyes helps find problems hidden by the forest.

Best wishes

aliciaDJones
- 5th September 2012, 06:06
Pleas tell me this form is except link after how long or how many posts.

Ioannis
- 5th September 2012, 07:53
Please stop spamming this forum.

See also your private messages.

Ioannis