View Full Version : help for serial communication pic to pic
jasem700
- 27th December 2008, 15:23
hello my friend
please who can help me for sample code to create serial communication between 16f84A to 16f84A when using SEROUT/SERIN
I want to send a decimal number (0000 to 9999) from one PIC to the other where it's display it on 7 segment display 4 digit as shown in pictur attached
you can email my
[email protected]
and thankyou very much
mat janssen
- 27th December 2008, 17:34
Try serout for the first pic and serin for the second pic.
How to use serout and serin is in the manual that came with the compiler.
Ioannis
- 28th December 2008, 17:01
Do you have the rest of the program set up? I mean the display is working?
For the data just use something like:
Serout portpin,speed,["#",word_variable]
Serin portpin,speed,["#"],word_variable
For the parameters, have a look at the manual. I'd recommend a low speed of T2400.
Ioannis
jasem700
- 3rd January 2009, 14:42
thanks all my friends
I have this subroutine for display decimal number on 7 segement 4 digit
for examlpe when I try to display 1230 in proteuse simulation is not work properly
I have tow problem:
1-correct subroutine for displaying decimal number
2-and how I can include this subroutine with commands Serout serin in tow pic when first pic (transemetre) send decimal number the second pic (receiver) must receive it and display it on 7 segment 4 digit
and thank you very much for your help
subroutine to display decimal number
w1 var word
b0 var byte
TRISA=%00000000
TRISB=%00000000
loop:
w1=1230
gosub disp
goto loop
disp:
B0 = W1 / 1000 ' Find number of thousands
W1 = W1 // 1000 ' Remove thousands from W1
Gosub bin2seg ' Convert number to segments
Poke PortB, B0 ' Send segments to LED
Poke PortA, $17 ' Turn on fourth digit
Pause 1 ' Leave it on 1 ms
Poke PortA, $1F ' Turn off digit to prevent ghosting
B0 = W1 / 100 ' Find number of hundreds
W1 = W1 // 100 ' Remove hundreds from W1
Gosub bin2seg ' Convert number to segments
Poke PortB, B0 ' Send segments to LED
Poke PortA, $1B ' Turn on third digit
Pause 1 ' Leave it on 1 ms
Poke PortA, $1F ' Turn off digit to prevent ghosting
B0 = W1 / 10 ' Find number of tens
W1 = W1 // 10 ' Remove tens from W1
Gosub bin2seg ' Convert number to segments
Poke PortB, B0 ' Send segments to LED
Poke PortA, $1D ' Turn on second digit
Pause 1 ' Leave it on 1 ms
Poke PortA, $1F ' Turn off digit to prevent ghosting
B0 = W1 ' Get number of ones
Gosub bin2seg ' Convert number to segments
Poke PortB, B0 ' Send segments to LED
Poke PortA, $1E ' Turn on first digit
Pause 1 ' Leave it on 1 ms
Poke PortA, $1F ' Turn off digit to prevent ghosting
Return ' Go back to caller
' Convert binary number in B0 to segments for LED
bin2seg: Lookup B0,[$40,$79,$24,$30,$19,$12,$02,$78,$00,$18],B0
Return
jasem700
- 12th January 2009, 14:38
I wait for your help ........
Archangel
- 13th January 2009, 06:26
Hello jasm700,
You want to look at the manual sect 4.17.7 it explains how to use the DIG command to get your digit.
jasem700
- 26th February 2009, 14:17
ok thanks all my friend i will try your suggetions
SOMRU
- 27th February 2009, 16:06
This is what i use to drive my 8 digit dual display
Hope it helps.
By adjusting f & f2 you can adjust the brightness...
'REV 071408 * #disdrive9.01 DISPLAY LED DRIVER
DEFINE OSC 20
DEFINE SER2_BITS 8
A VAR BYTE
B VAR BYTE
C VAR BYTE
F VAR BYTE
F2 VAR BYTE
DCP VAR BYTE
AMP VAR WORD
TIME VAR WORD
COUNTA VAR WORD
COUNTB VAR WORD
COUNTC VAR WORD
SNO1 VAR WORD
SNO2 VAR WORD
FLOW7 VAR PORTA.0
DAT7 VAR PORTA.1
SPF10 VAR PORTA.2
BURN VAR PORTA.3
SPF02 VAR PORTA.4
SPF03 VAR PORTA.5
SEGMENT VAR PORTB
DIGIT VAR PORTC
TRISA = %11111111
TRISB = %00000000
TRISC = %00000000
ADCON0 = %00000000
ADCON1 = %00000111
A = 0
C = 0
B = 0
F = 100
F2 = 3
DCP = 0
PAUSE 20
TIME = 1234
AMP = 5678
EEPROM 0,[129,243,73,97,51,37,5,241,1,49,254,253,251,247,239 ,223,191,253]
GOSUB BSEQ
LOOP: ' AND NOW THE MAIN EVENT
IF FLOW7 = 1 THEN
SerIN2 PORTA.1,84,[TIME.highbyte,TIME.lowbyte,AMP.highbyte,AMP.lowbyt e,DCP]
ENDIF
IF DCP = 9 THEN
GOSUB BSEQ
ENDIF
FOR C = 0 TO 4
READ TIME DIG C,SEGMENT
LOOKUP C,[$BF,$7F,$DF,$EF],DIGIT
IF C = 4 THEN
PORTB = %11111110
IF DCP = 1 THEN DIGIT = $EF
IF DCP = 2 THEN DIGIT = $DF
IF DCP = 3 THEN DIGIT = $7F
IF DCP = 4 THEN DIGIT = $BF
ENDIF
PAUSEUS f
PORTB = $FF
PORTC = $FF
PAUSEUS F2
NEXT C
FOR B = 0 TO 4
READ AMP DIG B,SEGMENT
LOOKUP B,[$FE,$FD,$FB,$F7],DIGIT
IF B = 4 THEN
PORTB = %11111110
IF DCP = 5 THEN DIGIT = $FE
IF DCP = 6 THEN DIGIT = $FD
IF DCP = 7 THEN DIGIT = $FB
IF DCP = 8 THEN DIGIT = $F7
ENDIF
PAUSEUS f
PORTB = $FF
PORTC = $FF
PAUSEUS F2
NEXT B
GOTO LOOP
BSEQ: FOR A=0 TO 3
FOR C = 0 TO 6
READ C+11,SEGMENT
LOOKUP A,[$EF,$DF,$7F,$BF],DIGIT
PAUSEUS 1000
PORTB = $FF
PORTC = $FF
PAUSE 10
NEXT C
PAUSE 2
NEXT A
FOR A=0 TO 3
FOR B = 6 TO 0 STEP -1
READ B+11,SEGMENT
LOOKUP A,[$FE,$FD,$FB,$F7],DIGIT
PAUSEUS 1000
PORTB = $FF
PORTC = $FF
PAUSE 10
NEXT B
PAUSE 2
NEXT A
DCP = 1
RETURN
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.