Professional Documents
Culture Documents
decoder driver
' It also incorporates placing of Decimal point.
' A PICmicro with on-board eeprom
Device 16F876A
Include "Modedefs.bas"
XTAL = 20 ' Set Xtal
Frequency
' ** Declare Pins Used **
Symbol Clk = PORTB.1 ' Data is clocked on
rising edge of this pin
Symbol Dta = PORTB.2 ' Bits are
shifted out of this pin
Symbol Load = PORTB.3
Symbol RecEnable = PORTC.2
Symbol SWS = PORTB.0 ' start switch
Symbol Sol_Low = PORTB.4 'Low soleniod
Symbol Sol_Mid = PORTB.5 ' medium solenoid
Symbol Sol_Hig = PORTB.6 ' High sole
' ** Declare Constants **
Dim Kg_grams1 As DWord
' DIM Address as BYTE
' Dim AD_Raw as Word ' 10-bit result
of A/D conversion
' Dim AD_Result as Word ' Quantasized ADC
result
' Dim Average as Word ' Build up the
average result
' Dim Samples as Byte
Dim Rate As 3129
' Rate1 var word
Dim Flow_rate As Word
Dim Kg As DWord
Dim Kg1 As DWord
Dim Amount As DWord
' DIM Kgc as Dword
Dim Kgdis As DWord
Dim L_Kg As DWord
Dim L_Sale As DWord
Dim Totalizer As DWord
Dim Rate2 As Word
Dim cal_fact As Byte
LTMSW var Word
MTHSW var Word
Dim Low_flow_cut As Word
Dim cons1 As 10
Dim cons2 As 1000
Dim cons3 As 10000
Dim cons4 As 10000000
Dim conav As 30
Dim i As Byte
Digit Var Byte
R_Val Var Byte
' Flow_rate var word
Disp_Bot var Word
register3 var Word
register4 var Word
register5 var Word
register6 var Word
Kg_grams var Word
register8 var Word
Dim Kg_grams_old As Word
Dim Flow_rate_old As Word
' Totalizer var word
Dim LastSale As DWord
Dim LSale As DWord
Dim Flag As Byte
Dim Lcd_top[8] As Word
Dim Lcd_mid[8] As Word
Dim Lcd_bot[8] As Word
Dim Seg[8] As Word
Dim SegA[8] As Word
Dim SegB[8] As Word
Dim Disp_Patt As Word
Dim CoilTx[8] As Byte
Dim CoilRx[8] As Byte
a var Byte
c var Byte
d var Byte
Dim DataTX[8] As Byte
Dim RX[23] As Byte
CRC16 var Word
Disp_top var DWord
Disp_mid var DWord
' Disp_bot var word
SEG1 var Byte
SEG2 var Byte
SEG3 var Byte
SEG4 var Byte
SEG5 var Byte
SEG6 var Byte
SEG7 var Byte
SEG8 var Byte
SEG9 var Byte
SEG10 var Byte
SEG11 var Byte
SEG12 var Byte
SEG13 var Byte
SEG14 var Byte
SEG15 var Byte
SEG16 var Byte
rat_flag var Byte
TRISA = %00000011 ' Configure AN0 (PORTA.0) as
an input
TRISB = %00000001
TRISC = %10000000
ADCON1 = %10000100
CoilTx[0]=$01
CoilTx[1]=$05
CoilTx[2]=$00
CoilTx[3]=$02
CoilTx[4]=$FF
CoilTx[5]=$00
CoilTx[6]=$2D
CoilTx[7]=$FA
DataTX[0]=$01
DataTX[1]=$03
DataTX[2]=$00
DataTX[3]=$01
DataTX[4]=$00
DataTX[5]=$09
DataTX[6]=$D4
DataTX[7]=$0C
PortB=0
Portc=0
PortA=0
'EWRITE 100, [100]
'EWRITE 105, [400]
rat_flag=0
DelayMS 2000
SHOut Dta,Clk,msbfirst,
[0,119,88,109,121,120,0,0,118,89,121,120,0,0,0,0]
High Load
Low Load
DelayMS 5000
** Subroutines **
' Display the Value held in the Variable "MAX_DISP" on the four LED's
' The value held in "MAX_DP" places the decimal point on that LED (0-3)
' Sending the value 15 blanks the display, this allows Zero suppression
' By setting bit-7 of the value sent to the individual LED displays,
the decimal point
' Is illuminated
Transfer:
For i = 0 To 5
Lcd_top[i]=Disp_top Dig i
LookUpL Lcd_top[i],[95,6,59,47,102,109,124,7,127,103,0],Disp_Patt
Seg[i]=Disp_Patt
Next i
For i = 0 To 5
Lcd_mid[i]=Disp_mid Dig i
LookUpL Lcd_mid[i],[95,6,59,47,102,109,124,7,127,103,0],Disp_Patt
SegA[i]=Disp_Patt
Next i
'If rat_flag=1 then goto display_1
For i = 0 To 3
Lcd_bot[i]=Disp_bot Dig i
LookUpL Lcd_bot[i],[95,6,59,47,102,109,124,7,127,103,0],Disp_Patt
SegB[i]=Disp_Patt
Next i
display_1: SEG1=Seg[0]
SEG2=Seg[1]
SEG3=Seg[2]
SEG4=Seg[3]
SEG5=Seg[4]
SEG6=Seg[5]
SEG7=SegA[0]
SEG8=SegA[1]
SEG9=SegA[2]
SEG10=SegA[3]
SEG11=SegA[4]
SEG12=SegA[5]
SEG13=SegB[0]
SEG14=SegB[1]
SEG15=SegB[2]
SEG16=SegB[3]
SHOut Dta,Clk,msbfirst,
[SEG1,SEG2,SEG3,SEG4,SEG5,SEG6,SEG7,SEG8,SEG9,SEG10,SEG11,SEG12,SEG13,SE
G14,SEG15,SEG16]
High Load
pause 50
Return
'Delayms 20
CRC16_Calculate:
CRC16=$ffff
For c=0 To 20
CRC16=CRC16^RX[c]
For d=1 To 8
If CRC16.0=1 Then
CRC16=$A001^(CRC16>>1)
Else
CRC16=CRC16>>1
EndIf
Next d
Next c
Return
Total: DelayMS 1000
Totalizer=Totalizer+ Kg_grams1
EWrite 110 , [ Totalizer ]
DelayMS 500
If SWS= 0 Then GoTo Again
GoTo Main