; --------------------------------------------------------------------- ; 8749 to serial line EPROM reader for 8051 type processors. ; ; $Id: kbdbabel_8749_reader_8051.asm,v 1.1 2009/01/25 01:08:05 akurz Exp $ ; ; Clock/Crystal: 24MHz ; alternatively 3.6864MHz or its multiples. ; ; Serial line connect: ; RxD - p3.0 (Pin 10 on DIL40, Pin 2 on AT89C2051 PDIP20) ; TxD - p3.1 (Pin 11 on DIL40, Pin 3 on AT89C2051 PDIP20) ; ; 87C49 connect: ; DB0-DB7 (pin12-19) - p1.0-p1.7 (use 4k7 pull-ups on p1.0 and p1.1) ; P20-P22 (pin21-23) - p3.2-p3.4 ; T0,_RESET_ (pin1,4) - p3.5 ; XTAL1 (pin2) - 3-4MHz ; EA (pin7) - 18V ; Vdd (pin26) - Vcc ; Vcc (pin40) - Vcc ; Vss (pin20) - GND ; ; Build using the macroassembler by Alfred Arnold ; $ asl -L kbdbabel_87c49_reader_8051.asm -o kbdbabel_87c49_reader_8051.p ; $ p2bin -l \$ff -r 0-\$7ff kbdbabel_87c49_reader_8051 ; write kbdbabel_87c49_reader_8051.bin on an empty 27C256 or AT89C2051 ; ; Copyright 2009 by Alexander Kurz ; ; This is free software. ; You may copy and redistibute this software according to the ; GNU general public license version 3 or any later verson. ; ; --------------------------------------------------------------------- cpu 8052 include stddef51.inc include kbdbabel_intervals.inc ;---------------------------------------------------------- ; Variables / Memory layout ;---------------------------------------------------------- ;------------------ octets B20 sfrb 20h ; bit adressable space B21 sfrb 21h B22 sfrb 22h BitCountL equ 23h BitCountH equ 24h ;------------------ bits billyTheBit bit B20.0 ; demo ;------------------ stack StackBottom equ 50h ; the stack ;---------------------------------------------------------- ; start ;---------------------------------------------------------- org 0 ; cold start ljmp Start ;---------------------------------------------------------- ; interrupt handlers ;---------------------------------------------------------- ;---------------------------- ; org 03h ; external interrupt 0 ; ljmp HandleInt0 ;---------------------------- ; org 0bh ; handle TF0 ; ljmp HandleTF0 ;---------------------------- ; org 13h ; Int 1 ; ljmp HandleInt1 ;---------------------------- ; org 1bh ; handle TF1 ; ljmp HandleTF1 ;---------------------------- ; org 23h ; RI/TI ; ljmp HandleRITI ;---------------------------- ; org 2bh ; handle TF2 ; ljmp HandleTF2 org 033h ;---------------------------------------------------------- ; helper, waste 20 cpu cycles ; note: call and return takes 4 cycles ;---------------------------------------------------------- nop20: nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop ret ;---------------------------------------------------------- ; helper, waste 200 cpu cycles ; note: call and return takes 4 cycles ;---------------------------------------------------------- nop200: acall nop20 acall nop20 acall nop20 acall nop20 acall nop20 acall nop20 acall nop20 acall nop20 acall nop20 ret ;---------------------------------------------------------- ; init uart with timer 1 as baudrate generator ; need 9600BPS ; ; --- dirty 9.6kbps ; precisely this is 9.6152kbps, 0.15% off the correct bitrate ; 9600BPS @24MHz -> tl1 and th1 = #243 with SMOD=1 ; (256-2*24000/384/9.6) uart_t1_9600_24M equ 243 ; ;---------------------------------------------------------- uart_timer1_init: mov scon, #050h ; uart mode 1 (8 bit), single processor orl tmod, #020h ; M0,M1, bit4,5 in TMOD, timer 1 in mode 2, 8bit-auto-reload orl pcon, #080h ; SMOD, bit 7 in PCON mov th1, #uart_t1_9600_24M mov tl1, #uart_t1_9600_24M clr es ; disable serial interrupt setb tr1 clr ri setb ti ret ;---------------------------------------------------------- ; Id ;---------------------------------------------------------- RCSId DB "$Id: kbdbabel_8749_reader_8051.asm,v 1.1 2009/01/25 01:08:05 akurz Exp $" ;---------------------------------------------------------- ; main ;---------------------------------------------------------- Start: ; -- init the stack mov sp,#StackBottom ; -- init UART and timer0/1 acall uart_timer1_init ; -- disable interrupts int0 clr ea ; -- clear all flags mov B20,#0 mov B21,#0 mov B22,#0 mov BitCountL,#0 mov BitCountH,#0 setb p3.5 acall nop200 acall nop200 acall nop200 acall nop200 acall nop200 acall nop200 clr p3.5 acall nop200 acall nop200 acall nop200 acall nop200 acall nop200 acall nop200 ; ---------------- loop: ; -- clr t0 clr p3.5 acall nop200 ; -- write 11 address-bits mov a,BitCountH mov c,acc.0 mov p3.2,c mov c,acc.1 mov p3.3,c mov c,acc.2 mov p3.4,c mov a,BitCountL mov p1,a acall nop200 acall nop200 ; -- set t0 setb p3.5 acall nop200 ; dirty hack: the 8749 seems not to be able to pull up 89c2051 lines mov a,0ffh mov p1,a acall nop200 acall nop200 ; -- UART ready? loop_waitfor_uart: jnb TI,loop_waitfor_uart ; -- read and send data mov a,p1 mov sbuf,a clr TI ; -- inc addr mov a,BitCountL inc a mov BitCountL,a jnz loop_inc_done mov a,BitCountH inc a anl a,#07h mov BitCountH,a jnz loop_inc_done ; -- infinite Loop to stop here loop_stop_here: clr p3.5 sjmp loop_stop_here loop_inc_done: sjmp loop ;---------------------------------------------------------- ; Still space on the ROM left for the license? ;---------------------------------------------------------- LIC01 DB " Copyright 2009 by Alexander Kurz" LIC02 DB " " GPL01 DB " This program is free software; you can redistribute it and/or modify" GPL02 DB " it under the terms of the GNU General Public License as published by" GPL03 DB " the Free Software Foundation; either version 3, or (at your option)" GPL04 DB " any later version." GPL05 DB " " GPL06 DB " This program is distributed in the hope that it will be useful," GPL07 DB " but WITHOUT ANY WARRANTY; without even the implied warranty of" GPL08 DB " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" GPL09 DB " GNU General Public License for more details." GPL10 DB " " ; ---------------- end