PDA

View Full Version : help with 16f628a



thalia
- 22nd April 2006, 10:00
hello forum!

Any help will be apreciated, I new to pic programming, and do not know where to start,
a code sample will be apreciated.
I can modify it and compleate the program if you give a code sample for this particular PIC
I been trying other code samples but they are too generic and could not made them work.


Here is my project: using a pic16F628A.
I need to write a program to do the following:

1.- Store in memory a number between 1-256 and remain safe in memory even when no power,
and using PORTB.0 increase it by one every time I push a button, and DEcrease it by pushing another buttom at PORTB.7
This update should be available only for a few seconds after first powering the circuit
and the NEW number should remain safe even if no power.


Here is the challenging part:
at all times AND AT THE SAME TIME I need to TURN ON a led conected to those PORTB.0 and PORTB.7
(because of the visual effect the LED don't have to be ON while readding the button to apear lighted)


after a few seconds of not pressing those buttons to update the number, the program will go to the next phase,
and the number CAN NOT be access antil circuit is power OFF and back ON

2.- the number stored in the NON volatil memory (explained in step 1) will represent minutes.
withOUT the use of any external timing components.
A rutine will COUNT DOWN secons and minutes until ZERO time is reach.
while time still left a logical high signal (+5V) is needed to be present at PORTA.1

and finally

3.- AT ANY TIME WITH OR WITHOUT TIME LEFT, A logical LOW signal (0v) at PORTA.2
will reset the count down to start all over again from the begining.

thalia
- 23rd April 2006, 07:20
if this is too much to ask, just........please show me how to read/write to the non volatile part of the pic 16f628a memory.

how to rear a button from a port

how to output a high/low to a port

how to use the timer

all of this to the pic16f628a

please, please.

thanks in advance for any an all your help, and for taking time of your busy schedule to read my questions and requests

Melanie
- 23rd April 2006, 08:58
Here is some code to get you started...



@ DEVICE pic16F628A, INTRC_OSC_NOCLKOUT
@ DEVICE pic16F628A, WDT_ON
@ DEVICE pic16F628A, PWRT_ON
@ DEVICE pic16F628A, MCLR_OFF
@ DEVICE pic16F628A, BOD_ON
@ DEVICE pic16F628A, LVP_OFF
@ DEVICE pic16F628A, CPD_OFF
@ DEVICE pic16F628A, PROTECT_OFF

ButtonA var PortA.0 ' Button connected between PIC pin and Vss
' Resistor (10K) connected between PIC pin and Vdd

LEDA var PortA.1 ' LED connected between Vdd and PIC pin
' via 330R Resistor
' Anode end of LED towards Vdd and Kathode to PIC pin

TRISA=%00000001
CMCON=%00000111

Loop:
If ButtonA=0 then
Low LEDA
else
High LEDA
endif
Goto Loop

End


Press the Button and LED will light. Release the Button and the LED will go out.

I have you shown with this piece of code how to read an INPUT from a press-button, and how to OUTPUT to control an LED. The @ DEVICE statements will configure your PIC for internal Oscillator and internal MCLR so it will work the moment you apply power to it.

Look-up each command/instruction I have used either in the PICBasicPro Manual or the Datasheet.

It is now UP TO YOU to logically design how your program will work. The PBP Manual and the PICs Datasheet are essential reading.

thalia
- 3rd May 2006, 08:16
After a couple of days of working NON stop (and no sleep) I finally finished my project, IT's working, It's working.......thanks a lot for the help, it was fun to learn.

the core of the project was to activate a count down timer when ONE or TWO push buttons are pressed, each one should have it's own independent time (the amount of time can be change by the user using the same TWO push buttons right after power on and after the user quit pressing for adjusment or if (s)he doesn't press them at all, then the new time is stored in the eeprom memory), further more every time the button(s) is(are) pressed it will increment the time left and this could happend at any time and many times, the time left for each button has to be displayed in four 7-segments display LEDs with MM:SS format if only one button is pressed of one of the two has run out of time, and in M1:M2 if the two have time left. also a count of every push has to be stored in EEPROM memory to be displayed at will by the user, at the power up of the circuit (either the user adjust the time per push, or want to know the amount of pushes has been so far), and finally while there is time left a relay stays ON to activate an external device (ONE PER EACH OF THE TWO USERS)

ONE THING, since this was my very first pic programming I did NOT use any interrupts for the clock, instead I wrote the program and when I had all finished and working the clock was NOTa real clock ticking every second but instead way to much faster, so my solution was to timed ONE minute of real time against the minutes displayed, and based on that I "IF'ed the program to not enter the decrement seconds seccion until a number of program cicles were reach. and to my surprise and GOOD luck a got a very close aproximation of the time (one second short every five MINUTES of real time, wich for my aplication it's an acceptable error).

and even the project is finished and working, I was wondering if you could give me an code example of how to use interrups to measure time.

regards
and thanks for the help