PDA

View Full Version : PIC16F84(A) counter



nmmr
- 25th May 2005, 17:03
Hi there to you all

I've a question, that maybe anyone can help...

I want to make a counter/display, that has to be able to display a number from 1 to 512, at users choice, store it on eeprom, for later use and if the user wants, he can make it go up or down, by a push button.
Ex. it is displaying "050" and when we push the up button it should show "051", or in the other way "049", flash 4 or 5 times, and then show it continuasly, and storing it for later. For now, for testing I'm using a constant value.

I had read that in 16F84 I can use the EREAD and EWRITE to store my variable in the eeprom, so that when I power off the circuit, it stays there for later reading it.

I already try to display some digits to 3 - 7 segment displays, using 4 data lines through a 4511, and 3 transistors for multiplexing, and I'm using the folowing sub-routine code to do that:

DEVICE = 16F84a
XTAL = 4

DIM ST_ADRESS AS WORD
DIM N_CHANS AS BYTE
DIM VEZ AS BYTE
DIM CENTENAS AS BYTE
DIM DEZENAS AS BYTE
DIM UNIDADES AS BYTE
DIM DIGIT AS BYTE
SYMBOL UP_ADRESS PORTA.1
SYMBOL DW_ADRESS PORTA.0


DELAYMS 600 'ESPERAR POR ESTABILIZAÇÃO DO PIC
GOSUB TESTE_DISPLAY
ST_ADRESS = 95 'EREAD 0
N_CHANS = 1
IF ST_ADRESS > 512 - N_CHANS THEN
ST_ADRESS = 512 - N_CHANS
END IF

DELAYMS 1500


TEST_ADRESS:
IF UP_ADRESS = 1 OR DW_ADRESS = 1 THEN
STOP
ELSE
GOSUB MOSTRA_DISP
GOTO TEST_ADRESS
END IF

STOP

TESTE_DISPLAY:
FOR VEZ = 1 TO 4
CLEAR PORTB 'LIMPAR PORTA
DELAYMS 500
HIGH PORTB.4 'ACTIVAR DISPLAYS
HIGH PORTB.5
HIGH PORTB.6
LOW PORTB.0 'ESCREVER 888s
LOW PORTB.1
LOW PORTB.2
HIGH PORTB.3
NEXT
RETURN

MOSTRA_DISP:
IF ST_ADRESS < 100 THEN
CENTENAS = 0
DEZENAS = ST_ADRESS DIG 1
UNIDADES = ST_ADRESS DIG 0
ELSEIF ST_ADRESS < 10 THEN
CENTENAS = 0
DEZENAS =0
UNIDADES = ST_ADRESS
ELSE
CENTENAS = ST_ADRESS DIG 2
DEZENAS = ST_ADRESS DIG 1
UNIDADES = ST_ADRESS DIG 0
END IF

FOR VEZ = 1 TO 3
IF VEZ = 1 THEN
HIGH PORTB.4
DIGIT = CENTENAS
ELSEIF VEZ = 2 THEN
HIGH PORTB.5
DIGIT = DEZENAS
ELSE
HIGH PORTB.6
DIGIT = UNIDADES
END IF
SELECT DIGIT
CASE 0
LOW PORTB.0
LOW PORTB.1
LOW PORTB.2
LOW PORTB.3
CASE 1
HIGH PORTB.0
LOW PORTB.1
LOW PORTB.2
LOW PORTB.3
CASE 2
LOW PORTB.0
HIGH PORTB.1
LOW PORTB.2
LOW PORTB.3
CASE 3
HIGH PORTB.0
HIGH PORTB.1
LOW PORTB.2
LOW PORTB.3
CASE 4
LOW PORTB.0
LOW PORTB.1
HIGH PORTB.2
LOW PORTB.3
CASE 5
HIGH PORTB.0
LOW PORTB.1
HIGH PORTB.2
LOW PORTB.3
CASE 6
LOW PORTB.0
HIGH PORTB.1
HIGH PORTB.2
LOW PORTB.3
CASE 7
HIGH PORTB.0
HIGH PORTB.1
HIGH PORTB.2
LOW PORTB.3
CASE 8
LOW PORTB.0
LOW PORTB.1
LOW PORTB.2
HIGH PORTB.3
CASE 9
HIGH PORTB.0
LOW PORTB.1
LOW PORTB.2
HIGH PORTB.3
END SELECT
NEXT
RETURN

I know, that there is some things left to do, but i'm trying one thing at time.

My problem is, how do I do the flashing of the user set number, and always showing/flashing it, and then go back again to normal mode... Do I have to use timers or something?

Any help will be good

Nuno

nmmr
- 25th May 2005, 17:11
For all of you to understand

CENTENAS - hundreds, holds the hundred digit of the number
DEZENAS - sets of tens
UNIDADES - units

Sorry, I'm from Portugal...

mister_e
- 26th May 2005, 04:27
Hi,
we can for sure help you if you're using Melabs PICBASIC PRO. BUT in your case, you should post your question Here (http://www.picbasic.org/forum/index.php?)