⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 telecard.asm

📁 This telecard reader can read the contain of any telecard until 64 bytes [ 512 bits ] and display i
💻 ASM
字号:
;	
;	
;		GREEK TELECARD READER
;		
;		Date: 	18-Sep-2002
;		Author: Serasidis Vasilis	
;		Target: AT90S1200 at 4MHz crystal
;		RS232:	19200 bps 8n1
;
;		Home:	http://www.serasidis.gr
;		email:	info@serasidis.gr
;
;
;
;
;***** Pin definitions

.equ	TxD	=0		;Transmit pin is PD0
.equ	Data	=2		;Input-Output pin is PD2
.equ	CLK	=3		;Clock pin is PD3
.equ	RST	=4		;Reset pin is PD4
.equ	SW	=5		;Switch for start reading the card is PD5
;***** Global register variables

.def	bitcnt	=R16		;bit counter
.def	temp	=R17		;temporary storage register
.def	temp2	=R20
.def	temp3	=R21
.def	Txbyte	=R18		;Data to be transmitted
.def	EEard	=R19		;EEPROM address to read from
.def	Tdata	=R22		;Telecards data

.cseg

reset:
	ldi	temp,0b11011001 ;PD1,PD2,PD5 inputs others outputs
	out	DDRD,temp
	ldi	temp,0xff
	out	DDRB,temp
	out	PORTD,temp	;Enable pullup resistors on PORT D
	
;--------------------------------------------------------------------------
;------------------         Type some messages          -------------------
;--------------------------------------------------------------------------

loop:	sbic	PIND,sw		;Read the switch 
	rjmp	loop

	cbi	PortD,rst		
	ldi	temp3,64	;Telecard capacity, 64 bytes (512 bits) 		

	ldi	txbyte,0x0c	;Clear the screen
	rcall	putchar
	ldi	txbyte,0x0a	;Insert empty Line 
	rcall	putchar
	ldi	eeard,0x10	

again:	rcall	eeread
	inc	eeard
	cpi	eeard,64
	brne	again
	ldi	txbyte,0x0d	;Enter
	rcall	putchar
	ldi	txbyte,0x0d	;Enter 
	rcall	putchar
	ldi	txbyte,0x0a	;Insert empty Line 
	rcall	putchar

	ldi	txbyte,0x0d	;Enter
	rcall	putchar
	ldi	txbyte,0x0d	;Enter 
	rcall	putchar
	ldi	txbyte,0x0a	;Insert empty Line 
	rcall	putchar

	ldi	txbyte,' '	;
	rcall	putchar
	ldi	txbyte,' '	;
	rcall	putchar
	ldi	txbyte,' '	;
	rcall	putchar
	ldi	txbyte,' '	;
	rcall	putchar
	ldi	txbyte,' '	;
	rcall	putchar
	ldi	txbyte,' '	;
	rcall	putchar
	ldi	txbyte,' '	;
	rcall	putchar

	ldi	txbyte,'1'	;
	rcall	putchar
	ldi	txbyte,'8'	;
	rcall	putchar
	ldi	txbyte,' '	;
	rcall	putchar
	ldi	txbyte,'S'	;
	rcall	putchar
	ldi	txbyte,'E'	;
	rcall	putchar
	ldi	txbyte,'P'	;
	rcall	putchar
	ldi	txbyte,' '	;
	rcall	putchar
	ldi	txbyte,'2'	;
	rcall	putchar
	ldi	txbyte,'0'	;
	rcall	putchar
	ldi	txbyte,'0'	;
	rcall	putchar
	ldi	txbyte,'2'	;
	rcall	putchar
	ldi	txbyte,' '	;
	rcall	putchar
	ldi	txbyte,'B'	;
	rcall	putchar
	ldi	txbyte,'y'	;
	rcall	putchar
	ldi	txbyte,' '	;
	rcall	putchar
	ldi	txbyte,'S'	;
	rcall	putchar
	ldi	txbyte,'E'	;
	rcall	putchar
	ldi	txbyte,'R'	;
	rcall	putchar
	ldi	txbyte,'A'	;
	rcall	putchar
	ldi	txbyte,'S'	;
	rcall	putchar
	ldi	txbyte,'I'	;
	rcall	putchar
	ldi	txbyte,'D'	;
	rcall	putchar
	ldi	txbyte,'I'	;
	rcall	putchar
	ldi	txbyte,'S'	;
	rcall	putchar
	ldi	txbyte,' '	;
	rcall	putchar
	ldi	txbyte,'V'	;
	rcall	putchar
	ldi	txbyte,'A'	;
	rcall	putchar
	ldi	txbyte,'S'	;
	rcall	putchar
	ldi	txbyte,'I'	;
	rcall	putchar
	ldi	txbyte,'L'	;
	rcall	putchar
	ldi	txbyte,'I'	;
	rcall	putchar
	ldi	txbyte,'S'	;
	rcall	putchar
	ldi	txbyte,0x0d	;Enter
	rcall	putchar
	ldi	txbyte,0x0d	;Enter 
	rcall	putchar
	ldi	txbyte,0x0a	;Insert empty Line 
	rcall	putchar
	ldi	txbyte,0x0a	;Insert empty Line 
	rcall	putchar

;--------------------------------------------------------------------------
;------------------         Reading of the card         -------------------
;--------------------------------------------------------------------------	
read_card:	
	
	clr	Tdata
	ldi	temp2,8		;8 bits length for the byte

next_bit:
	ror	Tdata		;Rotate right the Tdata register
	cbi	PortD,clk	;Clear the clock	
	sbic	PIND,data	;Read if the data pin, is '1'
	sbr	Tdata,0x80	;If yes, make '1' to the 8th bit of Tdata register
	sbi	PortD,clk	;Set the clock
	dec	temp2		;Decrease by 1 the temp2 register
	brne	next_bit	;If temp2 register its not 0, go to next_bit

;--------------------------------------------------------------------------
;---------   Modify the HEX value of the Tdata register to ASCII   --------   
;--------------------------------------------------------------------------

	mov	temp2,Tdata
	swap	temp2
	andi	temp2,0b00001111
	mov	eeard,temp2
	rcall	eeread

	mov	temp2,Tdata
	andi	temp2,0b00001111
	mov	eeard,temp2
	rcall	eeread
	ldi	txbyte,','
	rcall	putchar

	cpi	temp3,49	;Type the firt 16 bytes
	breq	next_line	;If its at the end, change line
	cpi	temp3,33	;Type the next 16 bytes
	breq	next_line	;If its at the end, change line
	cpi	temp3,17	;Type the next 16 bytes
	breq	next_line	;If its at the end, change line 

	dec	temp3		;Its the last byte (64th) ?
	brne	read_card	;If not, read the next byte
end:
	sbis	PIND,sw		;Read the switch 
	rjmp	end
	ldi	temp,255
	rcall	UART_delay1
	rjmp	reset

;--------------------------------------------------------------------------
next_line:
	ldi	txbyte,0x0d  	
	rcall	putchar
	ldi	txbyte,0x0a  	
	rcall	putchar

	dec	temp3		;Its the last byte (64th) ?
	brne	read_card	;If not, read the next byte

;--------------------------------------------------------------------------
;-------------------   Read the contain of the eeprom   -------------------   
;--------------------------------------------------------------------------
EERead:
	sbic	EECR,EEWE	;if EEWE not clear
	rjmp	EERead		;    wait more
	out	EEAR,EEard	;output address
;***** Issue EEPROM read strobe twice due to a bug in AVR!

	sbi	EECR,EERE	;set EEPROM Read strobe 
	in	Txbyte,EEDR	;get data
	rcall	putchar		;sent out char
	ret

;***************************************************************************
;*
;* "putchar"
;*
;* This subroutine transmits the byte stored in the "Txbyte" register
;* The number of stop bits used is set with the sb constant
;*
;* Number of words	:14 including return
;* Number of cycles	:Depens on bit rate
;* Low registers used	:None
;* High registers used	:2 (bitcnt,Txbyte)
;* Pointers used	:None
;*
;***************************************************************************
.equ	sb=2		;Number of stop bits (1, 2, ...)

putchar:
	sbi	PORTD,1
	ldi	bitcnt,9+sb	;1+8+sb (sb is # of stop bits)
	com	Txbyte		;Invert everything

	sec			;Start bit

putchar0:
	brcc	putchar1	;If carry set
	cbi	PORTD,TxD	;    send a '0'
	rjmp	putchar2	;else	

putchar1:
	sbi	PORTD,TxD	;    send a '1'
	nop

putchar2:
	rcall	UART_delay	;One bit delay
	rcall	UART_delay

	lsr	Txbyte		;Get next bit
	dec	bitcnt		;If not all bit sent
	brne	putchar0	;send next
	cbi	PORTD,1		;else
	ret			;return


;***************************************************************************
;*
;* "UART_delay"
;*
;* This delay subroutine generates the required delay between the bits when
;* transmitting and receiving bytes. The total execution time is set by the
;* constant "b":
;*
;*	3xb + 7 cycles (including rcall and ret)
;*
;* Number of words	:4 including return
;* Low registers used	:None
;* High registers used	:1 (temp)
;* Pointers used	:None
;*
;***************************************************************************
; Some b values: 	
;
; 1 MHz crystal:
;   9600 bps - b=14
;  19200 bps - b=5
;  28800 bps - b=2
;
; 2 MHz crystal:
;  19200 bps - b=14
;  28800 bps - b=8
;  57600 bps - b=2

; 4 MHz crystal:
;   9600 bps - b=62
;  19200 bps - b=31
;  28800 bps - b=19
;  57600 bps - b=8
; 115200 bps - b=2

;.equ	b=185		;9600 bps @ 11.0592 MHz crystal
.equ	b=31		;19200 bps @ 4 MHz crystal


UART_delay:
	ldi	temp,b
UART_delay1:
	dec	temp
	brne	UART_delay1
	ret

.eseg
.org 0
msg:	.db	"0123456789ABCDEF"
msg2:	.db	"   --- GREEK TELECARD (PHONECARD) READER ---", 0


.include "1200def.inc"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -