Kirjoittaja timo3 » 28 Marras 2007, 13:07
Tässä on se koodi, jolla luku onnistui. Resetointia on jatkettu muutamalla kellopulssilla ja tiedot lähetetään PC:lle 32 bitin sarjassa, eikä neljän bitin, niinkuin alussa.
Device 16F628
DECLARE XTAL 20
DECLARE CCP1.1 PORTB.3
CONFIG WDT_OFF , HS_OSC , PWRTE_ON, lvp_off
SYMBOL AuData3 = PORTB.7
SYMBOL AuData2 = PORTB.4
SYMBOL AuData1 = PORTB.6
SYMBOL AuData0 = PORTB.5
SYMBOL SerInput = PORTB.1
SYMBOL SerOutput = PORTB.2
SYMBOL AudRst = PORTB.0
SYMBOL Dir = PORTA.0
SYMBOL Audck_pin = PORTA.1
SYMBOL AudSynk = PORTA.3
dim Write_Byte as word
dim Read_Byte as word
dim AudData3_0 as byte
dim AudData7_4 as byte
dim AudData11_8 as byte
dim AudData15_12 as byte
dim AudData19_16 as byte
dim AudData23_20 as byte
dim AudData27_24 as byte
dim AudData31_28 as byte
Dim x as byte
cmcon = 7
Input Audck_pin
intcon.7 = 0
vrcon = 0
trisb = %11100011
pr2 = 255
ccp1con = %00001100
t2con = %00000101
CCPR1L = 127
output dir
output AudSynk
output AudRst
Input AuData3
Input AuData3
Input AuData2
Input AuData1
Input AuData0
Input Audck_pin
alku:
SerInput1:
Serin SerInput , 6 , [Write_Byte]
if Write_Byte = 75 then Write_Byte = "K"
serout SerOutput, 6 , [Write_Byte]
if Write_Byte = 75 then goto SerInput2
goto SerInput1
SerInput2:
FOR x = 1 to 8
Serin SerInput , 6 , [Write_Byte]
if Write_Byte = 75 then serout SerOutput, 6 , ["V"]
if Write_Byte = 75 then goto SerInput1
if Write_Byte = 48 then Write_Byte = 0
if Write_Byte = 49 then Write_Byte = 1
if Write_Byte = 50 then Write_Byte = 2
if Write_Byte = 51 then Write_Byte = 3
if Write_Byte = 52 then Write_Byte = 4
if Write_Byte = 53 then Write_Byte = 5
if Write_Byte = 54 then Write_Byte = 6
if Write_Byte = 55 then Write_Byte = 7
if Write_Byte = 56 then Write_Byte = 8
if Write_Byte = 57 then Write_Byte = 9
if Write_Byte = 65 then Write_Byte = 10
if Write_Byte = 66 then Write_Byte = 11
if Write_Byte = 67 then Write_Byte = 12
if Write_Byte = 68 then Write_Byte = 13
if Write_Byte = 69 then Write_Byte = 14
if Write_Byte = 70 then Write_Byte = 15
IF x = 8 then AudData3_0 = Write_Byte
IF x = 7 then AudData7_4 = Write_Byte
IF x = 6 then AudData11_8 = Write_Byte
IF x = 5 then AudData15_12 = Write_Byte
IF x = 4 then AudData19_16 = Write_Byte
IF x = 3 then AudData23_20 = Write_Byte
IF x = 2 then AudData27_24 = Write_Byte
IF x = 1 then AudData31_28 = Write_Byte
next
output AuData3
output AuData3
output AuData2
output AuData1
output AuData0
GOSUB Audck
high Dir
high AudSynk
low Dir
GOSUB Audck
LOW AudRst
GOSUB Audck
GOSUB Audck
GOSUB Audck
GOSUB Audck
GOSUB Audck
GOSUB Audck
GOSUB Audck
GOSUB Audck
HIGH AudRst
GOSUB Audck
GOSUB Audck
GOSUB Audck
GOSUB Audck
GOSUB Audck
GOSUB Audck
GOSUB Audck
GOSUB Audck
low AudSynk
LOW AuData3
LOW AuData2
LOW AuData1
LOW AuData0
GOSUB Audck
high AuData3
LOW AuData2
high AuData1
LOW AuData0
For x = 1 to 8
if x = 1 then Write_Byte = AudData3_0
if x = 2 then Write_Byte = AudData7_4
if x = 3 then Write_Byte = AudData11_8
if x = 4 then Write_Byte = AudData15_12
if x = 5 then Write_Byte = AudData19_16
if x = 6 then Write_Byte = AudData23_20
if x = 7 then Write_Byte = AudData27_24
if x = 8 then Write_Byte = AudData31_28
gosub Audck
if Write_Byte & 8 = 8 then high AuData3
if Write_Byte & 8 = 0 then low AuData3
if Write_Byte & 4 = 4 then high AuData2
if Write_Byte & 4 = 0 then low AuData2
if Write_Byte & 2 = 2 then high AuData1
if Write_Byte & 2 = 0 then low AuData1
if Write_Byte & 1 = 1 then high AuData0
if Write_Byte & 1 = 0 then low AuData0
next
GOSUB Audck
high Dir
input AuData3
input AuData2
input AuData1
input AuData0
Ready_Flaf:
GOSUB Audck
if AuData3 = 1 then goto Ready_Flaf
if AuData2 = 1 then goto Ready_Flaf
if AuData1 = 1 then goto Ready_Flaf
if AuData0 = 0 then goto Ready_Flaf
GOSUB Audck
high AudSynk
For x = 1 to 8
GOSUB Audck
Read_Byte = 0
Read_Byte = Read_Byte << 1
IF AuData3 = 1 THEN Read_Byte = Read_Byte + 1
Read_Byte = Read_Byte << 1
IF AuData2 = 1 THEN Read_Byte = Read_Byte + 1
Read_Byte = Read_Byte << 1
IF AuData1 = 1 THEN Read_Byte = Read_Byte + 1
Read_Byte = Read_Byte << 1
IF AuData0 = 1 THEN Read_Byte = Read_Byte + 1
if Read_Byte = 0 then Read_Byte = "0"
if Read_Byte = 1 then Read_Byte = "1"
if Read_Byte = 2 then Read_Byte = "2"
if Read_Byte = 3 then Read_Byte = "3"
if Read_Byte = 4 then Read_Byte = "4"
if Read_Byte = 5 then Read_Byte = "5"
if Read_Byte = 6 then Read_Byte = "6"
if Read_Byte = 7 then Read_Byte = "7"
if Read_Byte = 8 then Read_Byte = "8"
if Read_Byte = 9 then Read_Byte = "9"
if Read_Byte = 10 then Read_Byte = "A"
if Read_Byte = 11 then Read_Byte = "B"
if Read_Byte = 12 then Read_Byte = "C"
if Read_Byte = 13 then Read_Byte = "D"
if Read_Byte = 14 then Read_Byte = "E"
if Read_Byte = 15 then Read_Byte = "F"
IF x = 1 then AudData3_0 = Read_Byte
IF x = 2 then AudData7_4 = Read_Byte
IF x = 3 then AudData11_8 = Read_Byte
IF x = 4 then AudData15_12 = Read_Byte
IF x = 5 then AudData19_16 = Read_Byte
IF x = 6 then AudData23_20 = Read_Byte
IF x = 7 then AudData27_24 = Read_Byte
IF x = 8 then AudData31_28 = Read_Byte
next
serout SerOutput, 6 , [AudData31_28, AudData27_24, AudData23_20, AudData19_16, AudData15_12, AudData11_8, AudData7_4, AudData3_0,"L"]
goto alku
Audck:
If Audck_pin = 0 then goto Audck
Audck1:
If Audck_pin = 1 then goto Audck1
RETURN
end
Edited By timo3 on 1196248114
[color=#000000]Tässä on se koodi, jolla luku onnistui. Resetointia on jatkettu muutamalla kellopulssilla ja tiedot lähetetään PC:lle 32 bitin sarjassa, eikä neljän bitin, niinkuin alussa.
Device 16F628
DECLARE XTAL 20
DECLARE CCP1.1 PORTB.3
CONFIG WDT_OFF , HS_OSC , PWRTE_ON, lvp_off
SYMBOL AuData3 = PORTB.7
SYMBOL AuData2 = PORTB.4
SYMBOL AuData1 = PORTB.6
SYMBOL AuData0 = PORTB.5
SYMBOL SerInput = PORTB.1
SYMBOL SerOutput = PORTB.2
SYMBOL AudRst = PORTB.0
SYMBOL Dir = PORTA.0
SYMBOL Audck_pin = PORTA.1
SYMBOL AudSynk = PORTA.3
dim Write_Byte as word
dim Read_Byte as word
dim AudData3_0 as byte
dim AudData7_4 as byte
dim AudData11_8 as byte
dim AudData15_12 as byte
dim AudData19_16 as byte
dim AudData23_20 as byte
dim AudData27_24 as byte
dim AudData31_28 as byte
Dim x as byte
cmcon = 7
Input Audck_pin
intcon.7 = 0
vrcon = 0
trisb = %11100011
pr2 = 255
ccp1con = %00001100
t2con = %00000101
CCPR1L = 127
output dir
output AudSynk
output AudRst
Input AuData3
Input AuData3
Input AuData2
Input AuData1
Input AuData0
Input Audck_pin
alku:
SerInput1:
Serin SerInput , 6 , [Write_Byte]
if Write_Byte = 75 then Write_Byte = "K"
serout SerOutput, 6 , [Write_Byte]
if Write_Byte = 75 then goto SerInput2
goto SerInput1
SerInput2:
FOR x = 1 to 8
Serin SerInput , 6 , [Write_Byte]
if Write_Byte = 75 then serout SerOutput, 6 , ["V"]
if Write_Byte = 75 then goto SerInput1
if Write_Byte = 48 then Write_Byte = 0
if Write_Byte = 49 then Write_Byte = 1
if Write_Byte = 50 then Write_Byte = 2
if Write_Byte = 51 then Write_Byte = 3
if Write_Byte = 52 then Write_Byte = 4
if Write_Byte = 53 then Write_Byte = 5
if Write_Byte = 54 then Write_Byte = 6
if Write_Byte = 55 then Write_Byte = 7
if Write_Byte = 56 then Write_Byte = 8
if Write_Byte = 57 then Write_Byte = 9
if Write_Byte = 65 then Write_Byte = 10
if Write_Byte = 66 then Write_Byte = 11
if Write_Byte = 67 then Write_Byte = 12
if Write_Byte = 68 then Write_Byte = 13
if Write_Byte = 69 then Write_Byte = 14
if Write_Byte = 70 then Write_Byte = 15
IF x = 8 then AudData3_0 = Write_Byte
IF x = 7 then AudData7_4 = Write_Byte
IF x = 6 then AudData11_8 = Write_Byte
IF x = 5 then AudData15_12 = Write_Byte
IF x = 4 then AudData19_16 = Write_Byte
IF x = 3 then AudData23_20 = Write_Byte
IF x = 2 then AudData27_24 = Write_Byte
IF x = 1 then AudData31_28 = Write_Byte
next
output AuData3
output AuData3
output AuData2
output AuData1
output AuData0
GOSUB Audck
high Dir
high AudSynk
low Dir
GOSUB Audck
LOW AudRst
GOSUB Audck
GOSUB Audck
GOSUB Audck
GOSUB Audck
GOSUB Audck
GOSUB Audck
GOSUB Audck
GOSUB Audck
HIGH AudRst
GOSUB Audck
GOSUB Audck
GOSUB Audck
GOSUB Audck
GOSUB Audck
GOSUB Audck
GOSUB Audck
GOSUB Audck
low AudSynk
LOW AuData3
LOW AuData2
LOW AuData1
LOW AuData0
GOSUB Audck
high AuData3
LOW AuData2
high AuData1
LOW AuData0
For x = 1 to 8
if x = 1 then Write_Byte = AudData3_0
if x = 2 then Write_Byte = AudData7_4
if x = 3 then Write_Byte = AudData11_8
if x = 4 then Write_Byte = AudData15_12
if x = 5 then Write_Byte = AudData19_16
if x = 6 then Write_Byte = AudData23_20
if x = 7 then Write_Byte = AudData27_24
if x = 8 then Write_Byte = AudData31_28
gosub Audck
if Write_Byte & 8 = 8 then high AuData3
if Write_Byte & 8 = 0 then low AuData3
if Write_Byte & 4 = 4 then high AuData2
if Write_Byte & 4 = 0 then low AuData2
if Write_Byte & 2 = 2 then high AuData1
if Write_Byte & 2 = 0 then low AuData1
if Write_Byte & 1 = 1 then high AuData0
if Write_Byte & 1 = 0 then low AuData0
next
GOSUB Audck
high Dir
input AuData3
input AuData2
input AuData1
input AuData0
Ready_Flaf:
GOSUB Audck
if AuData3 = 1 then goto Ready_Flaf
if AuData2 = 1 then goto Ready_Flaf
if AuData1 = 1 then goto Ready_Flaf
if AuData0 = 0 then goto Ready_Flaf
GOSUB Audck
high AudSynk
For x = 1 to 8
GOSUB Audck
Read_Byte = 0
Read_Byte = Read_Byte << 1
IF AuData3 = 1 THEN Read_Byte = Read_Byte + 1
Read_Byte = Read_Byte << 1
IF AuData2 = 1 THEN Read_Byte = Read_Byte + 1
Read_Byte = Read_Byte << 1
IF AuData1 = 1 THEN Read_Byte = Read_Byte + 1
Read_Byte = Read_Byte << 1
IF AuData0 = 1 THEN Read_Byte = Read_Byte + 1
if Read_Byte = 0 then Read_Byte = "0"
if Read_Byte = 1 then Read_Byte = "1"
if Read_Byte = 2 then Read_Byte = "2"
if Read_Byte = 3 then Read_Byte = "3"
if Read_Byte = 4 then Read_Byte = "4"
if Read_Byte = 5 then Read_Byte = "5"
if Read_Byte = 6 then Read_Byte = "6"
if Read_Byte = 7 then Read_Byte = "7"
if Read_Byte = 8 then Read_Byte = "8"
if Read_Byte = 9 then Read_Byte = "9"
if Read_Byte = 10 then Read_Byte = "A"
if Read_Byte = 11 then Read_Byte = "B"
if Read_Byte = 12 then Read_Byte = "C"
if Read_Byte = 13 then Read_Byte = "D"
if Read_Byte = 14 then Read_Byte = "E"
if Read_Byte = 15 then Read_Byte = "F"
IF x = 1 then AudData3_0 = Read_Byte
IF x = 2 then AudData7_4 = Read_Byte
IF x = 3 then AudData11_8 = Read_Byte
IF x = 4 then AudData15_12 = Read_Byte
IF x = 5 then AudData19_16 = Read_Byte
IF x = 6 then AudData23_20 = Read_Byte
IF x = 7 then AudData27_24 = Read_Byte
IF x = 8 then AudData31_28 = Read_Byte
next
serout SerOutput, 6 , [AudData31_28, AudData27_24, AudData23_20, AudData19_16, AudData15_12, AudData11_8, AudData7_4, AudData3_0,"L"]
goto alku
Audck:
If Audck_pin = 0 then goto Audck
Audck1:
If Audck_pin = 1 then goto Audck1
RETURN
end[/color]
Edited By timo3 on 1196248114