'/////////////////////////////////////////////////////// '/// FAST Basic Compiler for AVR by MICRODESIGN /// '/// Exchange list Driver ver 1.0 okt.2001 /// '/// fast loading 4094 shift registers /// '/////////////////////////////////////////////////////// $Device= 8515 ' used device $Stack = 32 ' stack depth $Clock = 7.3728 ' used crystal $RC5=PORTA.0 $Sound=PORTD.5 $Timer1=Timer, Prescale=8 $Spi 4, Msb, Master, Low, Low $I2C SDA=PORTD.2, SCL=PORTD.3 $Baud=9600 $Def Strobe=PORTB.1 $Def test=PORTD.2 Dim buf(72) As Byte ' for 2 x 6 valutes 6 nums Dim bak(6) As Byte Dim p As Byte, prx As Byte ' p pointer to disp buf Dim adr As Byte Dim sys As Byte, comm As Byte ' used by IR receiving Dim col As Byte, c As Byte ' use by mux Dim n As Byte, rec As Byte Dim pika As Bit, first As Bit Dim ChGen As Flash Byte Dim w As Word Declare Sub Show() Declare Sub DoShow(k As Byte) Declare Sub Init() Declare Sub SaveAll() Declare Sub Edit() Declare Sub MemSet() Declare Sub Put(cif As Byte) Declare Function FromGen(i As Byte) As Byte Declare Interrupt Ovf1() Declare Interrupt Urxc() Const SysAdr=7 ' sys add of used IR Const NofN=6 ' N of chr in line Const Lines=6 ' N of Lines (valutes) Const NofDigits=35 ' (NofN * Line )-1 Const Disp=&h60 ' start of SRAM (buf) Const STX=&h02 ' Start Of Text Const EOT=&h04 ' End Of Text col=&h20 ' init value for mux PORTB=&hff DDRB=&hff PORTD.2=1 DDRD.2=1 Init() ' load disp from EE Enable Timer0 ' used by RC5 receiving Enable Timer1 ' mux timing Enable Urxc Enable Interrupts Start Timer1 Do RC5(sys, comm) ' scan IR sys=sys And &h1f ' cut toggle bit If sys=7 Then ' if our IR Sound 12, 100 Select Case comm Case 24 ' disp test Show() Init() ' restore display Case 22 ' go to edit p=101 ' first edit field Edit() SaveAll() End Select End If Loop '/////////////////////////////////////////////////////// Sub Show() ' animate display with numbers Local k As Byte For k=0 To 9 DoShow(k) Wait 1 Next End Sub '/////////////////////////////////////////////////////// Sub DoShow(k As Byte) ' fills display with numbers Local i As Byte, j As Byte For i=0 To Lines+1 For j=0 To NofN-1 Poke(disp+Lines*i+j, ChGen(k)) Next Next End Sub '/////////////////////////////////////////////////////// Sub Init() ' load display from EE Local i As Byte For i=0 To NofDigits Poke(disp+i, ReadEE(i+1)) Next End Sub '/////////////////////////////////////////////////////// Sub SaveAll() ' save display to EE Local i As Byte For i=0 To NofDigits WriteEE(i+1, Peek(disp+i)) Next End Sub '/////////////////////////////////////////////////////// Sub Edit() ' edit fields and clock/date Local old As Byte MemSet() Do RC5(sys, comm) ' scan IR If sys=7 Or sys=39 Then ' if right IR If sys=old Then ' and user releses key GoTo over Else Sound 10, 20 ' process key End If Else GoTo over End If Select Case comm Case 42 ' down MemCopy(NofN, VarPtr(bak), p-5) p=p+NofN If p=137 Then ' if bottom? p=101 ' then goto top End If MemSet() Case 52 ' up MemCopy(NofN, VarPtr(bak), p-5) p=p-NofN If p=95 Then ' if top? p=131 ' then goto bottom End If MemSet() Case 16 ' ENTER p=p+NofN If p=137 Then ' Or p=149 Then Exit Sub ' end editing Else MemSet() ' next fueld End If Case 34 ' 0 Put(0) Case 60 ' 1 Put(1) Case 50 ' 2 Put(2) Case 40 ' 3 Put(3) Case 30 ' 4 Put(4) Case 20 ' 5 Put(5) Case 10 ' 6 Put(6) Case 0 ' 7 Put(7) Case 54 ' 8 Put(8) Case 44 ' 9 Put(9) Case 24 ' . If Not pika Then Set pika ' just one dp per field n=Peek(p) n=n And &h7f Poke(p, n) Else Sound 5, 100 End If Case 22 ' out from edit MemCopy(NofN, VarPtr(bak), p-5) Exit Sub End Select over: old=sys Loop End Sub '/////////////////////////////////////////////////////// Sub MemSet() ' preserve curr field and disp cur Reset pika ' no dp yet in new field Set first ' first entry in new field MemCopy(NofN, p-5, VarPtr(bak)) MemLoad (p-5, &hff, &hff, &hff, &hff, &hff, &hfb) '&h90) End Sub '/////////////////////////////////////////////////////// Sub Put(cif As Byte) ' shift disp left & ins new num If Not first Then ' no shift for first entry (_) MemCopy(NofN, p-4, p-5) ' shift all left End If Reset first ' no more first entry Poke(p, ChGen(cif)) ' add new number End Sub '/////////////////////////////////////////////////////// Interrupt Ovf1(), Save 3 ' refreshes display Timer1=&hf533 ' 3ms na 7...MHz ' Timer1=&hdc00 '10ms na 7...MHz adr=Disp For n=1 To NofN SpiOut Peek(adr+c), Wait adr=adr+NofN Next SpiOut Not col ' power on column Shift(Right, 1, col) ' next column Incr c ' next column If c=NofN Then ' last column? c=0 ' yes, so from start col=&h20 End If Set Strobe: Set Strobe: Reset Strobe End Interrupt '/////////////////////////////////////////////////////// Interrupt Urxc(), Save 3 InputBin rec $Asm clr zh $End Incr prx Select Case rec Case 2 prx=95 Case 4 SaveAll() ' save new values in EE Case 32 ' leading spaces Poke(prx,&hff) ' as blanks Case 46 ' dp Decr prx n=Peek(prx) n=n And &h7f Poke(prx, n) Case 48 To 57 ' valid num n=rec-48 Poke(prx, ChGen(n)) End Select End Interrupt '/////////////////////////////////////////////////////// ChGen= &h90, &hfc, &ha2, &ha8, &hcc, &h89, &h81, &hbc, &h80, &h88