PDA

View Full Version : nedd help 16f84



malwww
- 2nd May 2009, 03:41
i use pic 16f84 and i want to send data by shiftout to the lcd .the problem is i dont know to use the variables for shiftout .i want to write a programe to count or digital clock i use 4 digit leds and ic 74hc164
this is the code please help
define _HS_OSC & _LVP_OFF & _WDT_OFF & _CP_OFF
define _BODEN_OFF & _MCLRE_ON & _PWRTE_ON

DEFINE OSC 20

INCLUDE "MODEDEFS.BAS"

TRISA = %00010000
TRISB = %00000000
PortA = $20
PORTB = 0
SDO VAR PortB.0
SCLK var PortB.1

Digit_1 var byte
Digit_2 var byte
Digit_3 var byte
Digit_4 var byte
Displays VAR WORD


Digit_1 = 0
Digit_2 = 0
Digit_3 = 0
Digit_4 = 0

data @ 0,252,96,218,242,102,182,190,224,254,246

LOOP:
COUNT PortA.4,1000,CounterTotal
DISPLAYS=0
DISPLAYS=(DISPLAYS+CounterTotal)
displays=(displays*6)

gosub Display
CounterTotal=0
GOTO LOOP


Display:
DIGIT_OUTPUT = DISPLAYS dig 0
READ DIGIT_OUTPUT, DIGIT_1
DIGIT_OUTPUT = DISPLAYS DIG 1
READ DIGIT_OUTPUT, DIGIT_2
DIGIT_OUTPUT = DISPLAYS DIG 2
READ DIGIT_OUTPUT, DIGIT_3
DIGIT_OUTPUT = DISPLAYS dig 3
READ DIGIT_OUTPUT, DIGIT_4

shiftout SDO,SCLK,0,[DIGIT_1\8,DIGIT_2\8,DIGIT_3\8,DIGIT_4\8]
pause 1000

return

END

Archangel
- 2nd May 2009, 05:03
Well you know good code when you borrow it, http://www.picbasic.co.uk/forum/showthread.php?t=9037
Now do something with it! Take it apart and see what makes it work.

shiftout SDO,SCLK,0,[DIGIT_1\8,DIGIT_2\8,DIGIT_3\8,DIGIT_4\8]
there is the statement sending info to the display, SDO & SCK are aliases to ports on the PIC.
DIGIT_1 DIGIT_2 . . . ARE the variable names containing the information, everything else is just counting and sorting the information. You say and I
i want to write a programe to count or digital clock i use 4 digit leds and ic 74hc164 This is not written to work that way, this is written to use SPI style readouts. Go back to that other thread and look at post 6 mister_e's code you will see how to strobe the displays . . . . here is the basic idea, your pic creates a pattern of a number across the output port, and lights 1 display, then repeats with a pattern for the next number and lights it . . . . and it does it so fast you cannot see the dark times.

malwww
- 2nd May 2009, 05:59
thank you very much joe for reply . i didnt inderstand good that code but if you dont mind please i want to know how to use the variable for read ..,b2
i want to read from 1 to 10 addresses to b2 every 1000 mlscnd 1 byte from data to b2 so the shiftout has pause 1000 then it will count from 0 to 9 on 1 digit so i will understandhow to (vary) between epprom data and b2 example
this is my last code i wrote now i can read from data to b2 and send it out to the digit but i need to count from 0 to 9 and pause between numbers please thank you so much



define _HS_OSC & _LVP_OFF & _WDT_OFF & _CP_OFF
define _BODEN_OFF & _MCLRE_ON & _PWRTE_ON



DEFINE OSC 4

Include "modedefs.bas"


B2 var byte
SDO VAR PortB.0
SCLK var PortB.1

TRISB = 0
TRISA = 1


Read 3,b2

main:

SHiftOUT SDO,SCLK,0,[B2\8]
pause 1000
goto main

end
data @ 0,252,96,218,242,102,182,190,224,254,246

all what i want is to know how to use variables like this so i will inderstand and i can carry on .

Archangel
- 2nd May 2009, 07:29
M E Labs ( the maker of your compiler ) has samples, and I think that is where this one came from as it has zero documentation ( as to ownership ). I suggest you look their site over, many samples there.

' READ and WRITE word variables to on-board EEPROM
'
' Word is used to add 1000 to each location address and store the
' result. The word data must be stored as 2 separate bytes.


INCLUDE "modedefs.bas" ' Include serial modes

SO VAR PORTC.6 ' Define serial output pin

B1 VAR BYTE ' Address variable
W2 VAR WORD ' Data variable


loop:

For B1 = 0 To 12 step 2 ' Step 2 because each word requires 2 bytes of memory
W2 = B1 + 1000 ' Add 1000 to address
Write B1, W2.HIGHBYTE ' Write high byte of word
Write B1+1, W2.LOWBYTE ' Write low byte of word to next address
Next B1

For B1 = 0 To 12 step 2 ' Step 2 to get word size data
Read B1, W2.HIGHBYTE ' Read high byte
Read B1+1, W2.LOWBYTE ' Read low byte
SerOut SO,T2400,[#W2," ",10,13] ' Display the word data
Next B1

SerOut SO,T2400,[10,13,10,13] ' Skip 2 Lines

GoTo loop ' Forever

you see a for next loop pointing to location in eprom to write or read from.

malwww
- 3rd May 2009, 03:31
thank you joe for helping im doing these examples, and i used buttoms to rite and read in the eeprom till now i will try to learn more well thank you again for helping,

Archangel
- 3rd May 2009, 05:12
thank you joe for helping im doing these examples, and i used buttoms to rite and read in the eeprom till now i will try to learn more well thank you again for helping,

Come back after you have tried those with more questions, the more you learn, the better your questions will get, and better teachers will step up.