Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

tv-tuner for 89c2051.asm -> c source?

Status
Not open for further replies.

z543g

Junior Member level 1
Joined
Jan 2, 2002
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
222
saa1064 asm

;**********************************************************
;* TUN_LED.ASM V1.0 *
;* Ansteuerung des Nokia-TV-Tuners 5827 (I2C-Bus) mittels *
;* des Mikrocontrollers AT89C2051 *
;* Softwareversion fuer LED-Display (mit SAA1064) *
;* Taste C/P: Umschaltung zwischen Anzeige der Programm- *
;* (Prxx) und der Kanalnummer (Chxx bzw. CCxx) *
;* Tasten + und -: Programm- bzw. Kanalnummer weiter- *
;* schalten: Pr00 bis Pr49 (nach Einschalten Pr01), *
;* Ch00 bis Ch69 sowie CC01 bis CC20 (Sonderkanaele) *
;**********************************************************
;* World Of Electronics *
;* http://www.woe.de.vu *
;* (c) WOE, 1999 *
;**********************************************************

; Anschluss der Tasten:
; P1. 7 6 5 4 3 2 1 0
; C/P + -

; P3. 7 5
; SDA SCL


t_cp equ p1.4 ; Taste C/P
t_plus equ p1.3 ; Taste Plus
t_minus equ p1.2 ; Taste Minus

sda equ p3.7
scl equ p3.5


i2c_ack_in equ 0 ; vom Slave gesendetes Acknowledge-Bit
i2c_ack_out equ 1 ; an den Slave zu sendendes Acknowledge-Bit
; jeweils 0=Ack, 1=kein Ack

prg equ 2 ; Flag fuer Channel/Program: 0->Ch., 1->Prg.
cc_nr equ 3 ; Flag fuer Sonderkanaele(CC): 0->Ch., 1->CC.


call ms100 ; Einschaltverzoegerung

setb i2c_ack_out
setb i2c_ack_in

mov r7,#1 ; Prg. Nr.
mov r6,#0 ; Ch. Nr.

setb prg
mov r0,#40
call i2c_start
mov a,#0a0h
call i2c_send
mov a,#0
call i2c_send
call i2c_start
mov a,#0a1h
call i2c_send
clr i2c_ack_out
init_prg:
call i2c_read

cjne a,#90,vgl ; wenn Ch.>89 dann Ch.=0
vgl:
jc vgl_end
clr a
vgl_end:

mov @r0,a
inc r0
cjne r0,#89,i1
setb i2c_ack_out
jmp init_prg
i1:
cjne r0,#90,init_prg
call i2c_stop

call get_ch
call disp_led
call tuner

abfrage:
call ms10
jnb t_minus,minus
jnb t_plus,plus
jnb t_cp,cp
jmp abfrage


minus:
jnb prg,chan_down
prg_down:
cjne r7,#0,r7_dec
mov r7,#49
jmp l1
r7_dec:
dec r7
l1:
call get_ch
call disp_led
call tuner
call ms10
minus_wait:
jnb t_minus,minus_wait
jmp abfrage


plus:
jnb prg,chan_up
prg_up:
cjne r7,#49,r7_inc
mov r7,#0
jmp l2
r7_inc:
inc r7
l2:
call get_ch
call disp_led
call tuner
call ms10
plus_wait:
jnb t_plus,plus_wait
jmp abfrage



chan_down:
cjne r6,#0,r6_dec
mov r6,#89
jmp l3
r6_dec:
dec r6
l3:
call save_ch
call disp_led
call tuner
call ms10
minus2_wait:
jnb t_minus,minus2_wait
jmp abfrage



chan_up:
cjne r6,#89,r6_inc
mov r6,#0
jmp l4
r6_inc:
inc r6
l4:
call save_ch
call disp_led
call tuner
call ms10
plus2_wait:
jnb t_plus,plus2_wait
jmp abfrage



cp:
jb prg,mode_ch
mode_prg:
setb prg
call store_eeprom
jmp cp_disp
mode_ch:
clr prg
cp_disp:
call disp_led
call ms10
cp_wait:
jnb t_cp,cp_wait
jmp abfrage



get_ch:
mov a,r7
add a,#40
mov r0,a
mov a,@r0
mov r6,a
cjne a,#70,cc_test
cc_test:
cpl c
mov cc_nr,c
ret



save_ch:
mov a,r7
add a,#40
mov r0,a
mov a,r6
mov @r0,a
cjne a,#70,cc_test2
cc_test2:
cpl c
mov cc_nr,c
ret



store_eeprom:
call i2c_start
mov a,#0a0h
call i2c_send
mov a,r7
call i2c_send
mov a,r6
call i2c_send
call i2c_stop
ret




disp_led:
mov dptr,#disp_tab
call i2c_start ; Daten auf Display schreiben
mov a,#70h ; Adresse SAA1064
call i2c_send
mov a,#0h ; Instructionbyte SAA1064
call i2c_send
mov a,#37h ; Controlbyte SAA1064
call i2c_send

jb prg,prg_nr
ch_nr:
mov a,r6
jnb cc_nr,d1
clr c
subb a,#69
jmp d1
prg_nr:
mov a,r7
d1:
mov b,#10
div ab
push acc
mov a,b
movc a,@a+dptr
call i2c_send

pop acc
movc a,@a+dptr
call i2c_send

jnb prg,ch_disp
pr_disp:
mov a,#17 ; "r"
movc a,@a+dptr
call i2c_send

mov a,#16 ; "P"
movc a,@a+dptr
call i2c_send
jmp d2

ch_disp:
jb cc_nr,cc_dis
mov a,#18 ; "h"
jmp dis
cc_dis:
mov a,#12 ; "C"
dis:
movc a,@a+dptr
call i2c_send

mov a,#12 ; "C"
movc a,@a+dptr
call i2c_send

d2:
call i2c_stop
ret



tuner:
call i2c_start
mov a,#0c2h ; Adresse PLL-Chip
call i2c_send

mov dptr,#freq_tab

mov a,r6 ; Channel-Nr.
rl a ; mit 2 multiplizieren
push acc
movc a,@a+dptr ; oberes Teilerbyte
anl a,#7fh
call i2c_send

pop acc
clr c
add a,#1
movc a,@a+dptr ; unteres Teilerbyte
call i2c_send

mov a,#10001110b ; charge-pump 50?, normal operation
call i2c_send

cjne r6,#4,c1 ; Ermittlung des Bandes
vhf1:
mov a,#4 ; VHF I
jmp band_ende
c1:
jc vhf1

cjne r6,#12,c2
vhf3:
mov a,#2 ; VHF III
jmp band_ende
c2:
jc vhf3

cjne r6,#69,c3
uhf:
mov a,#1 ; UHF
jmp band_ende
c3:
jc uhf

jmp vhf3 ; CC1..20


band_ende:

orl a,#11111000b
call i2c_send

call i2c_stop
ret



i2c_start: ; Start I2C
setb sda
nop
setb scl
call ms001

clr sda ; Data auf 0 (Start)
call ms001
clr scl ; Clock auf 0
call ms001
ret


i2c_stop: ; Stop I2C
call ms001
setb scl ; Clock auf 1
call ms001
setb sda ; Data auf 1 (Stop)
call ms001
ret



i2c_send: ; 1 Datenbyte senden
mov r3,#8
i2c_sloop:
rlc a
mov sda,c
call ms001
setb scl
call ms001
clr scl
call ms001
djnz r3,i2c_sloop
setb sda
call ms001
setb scl
call ms001
mov c,sda ; Acknowledge-Bit lesen
mov i2c_ack_in,c
clr scl
call ms001
clr sda
call ms001
ret



i2c_read: ; 1 Datenbyte empfangen
mov r3,#8
clr a
setb sda
i2c_rloop:
call ms001
setb scl
mov c,sda
rlc a
call ms001
clr scl
djnz r3,i2c_rloop
call ms001
mov c,i2c_ack_out ; Acknowledge-Bit senden
mov sda,c
call ms001
setb scl
call ms001
clr scl
call ms001
clr sda
call ms001
ret



ms001: ; Verzoegerung 10 us (bei 12MHz)
push acc
mov a,#2
ms001_1:
djnz acc,ms001_1
pop acc
ret




ms100: ; Verzoegerung 100 ms (bei 12 MHz)
push acc
mov a,r0
push acc
mov a,r1
push acc

mov r0,#100
ms100_2:
mov r1,#100
ms100_1:
nop
nop
nop
nop
nop
nop
nop
nop
djnz r1,ms100_1
djnz r0,ms100_2

pop acc
mov r1,a
pop acc
mov r0,a
pop acc
ret


ms10: ; Verzoegerung 10 ms (bei 12 MHz)
push acc
mov a,r0
push acc
mov a,r1
push acc

mov r0,#10
ms10_2:
mov r1,#100
ms10_1:
nop
nop
nop
nop
nop
nop
nop
nop
djnz r1,ms10_1
djnz r0,ms10_2

pop acc
mov r1,a
pop acc
mov r0,a
pop acc
ret



freq_tab:
; CH 0...4
db 0h,0h,5h,2h,5h,72h,5h,0E2h,6h,52h

; CH 5...12
db 0Dh,62h,0Dh,0D2h,0Eh,42h,0Eh,0B2h,0Fh,22h,0Fh,92h,10h,2h,10h,72h

; CH 13...20
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

; CH 21...27
db 1Fh,0E2h,20h,62h,20h,0E2h,21h,62h,21h,0E2h,22h,62h,22h,0E2h

; CH 28...34
db 23h,62h,23h,0E2h,24h,62h,24h,0E2h,25h,62h,25h,0E2h,26h,62h

; CH 35...41
db 26h,0E2h,27h,62h,27h,0E2h,28h,62h,28h,0E2h,29h,62h,29h,0E2h

; CH 42...48
db 2Ah,62h,2Ah,0E2h,2Bh,62h,2Bh,0E2h,2Ch,62h,2Ch,0E2h,2Dh,62h

; CH 49...55
db 2Dh,0E2h,2Eh,62h,2Eh,0E2h,2Fh,62h,2Fh,0E2h,30h,62h,30h,0E2h

; CH 56...62
db 31h,62h,31h,0E2h,32h,62h,32h,0E2h,33h,62h,33h,0E2h,34h,62h

; CH 63...69
db 34h,0E2h,35h,62h,35h,0E2h,36h,62h,36h,0E2h,37h,62h,37h,0E2h

; CC 1...7 (Sonderkanaele)
db 9h,2h,9h,72h,9h,0E2h,0Ah,52h,0Ah,0C2h,0Bh,32h,0Bh,0A2h

; CC 8...14
db 0Ch,12h,0Ch,82h,0Ch,0F2h,10h,0E2h,11h,52h,11h,0C2h,12h,32h

; CC 15...20
db 12h,0A2h,13h,12h,13h,82h,13h,0F2h,14h,62h,14h,0D2h




disp_tab: ; Code-Tabelle fuer Displayzeichen
; 0 1 2 3 4 5 6 7 8 9 A b C d E f
db 3Fh,06h,5Bh,4Fh,66h,6Dh,7Dh,07h,7Fh,6Fh,77h,7Ch,39h,5Eh,79h,71h

; P r h
db 73h,50h,74h


END

asm --> c language.
possible c sorcue? please!!
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top