Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
02/15/06 21:58
Read: times


 
#110102 - Formatted
Responding to: ???'s previous message
Please read the following instructions on how to post code so that the formatting is retained:
http://www.8052.com/forum/read.phtml?id=82476
Remember to use the 'Preview' button to check your text before 'Post'

; - Zero waitstates @ 38400 BAUD - (Transmit Delay 0 ms).

		$NOMOD51		;ignore standard SFR
		$INCLUDE(89S8252.MCU)	;recognize AT89S8252 SFR

CODE_MEM_MAIN	EQU	0100H		;main starts @ 0100H
LF		EQU	0AH		;line feed
CR		EQU	0DH		;carriage return
CLK		EQU 	P2.4		;display clock signal
EN		EQU 	P2.2		;display enable signal
DD_BUS		EQU 	P2.0		;display databus
DPL		EQU	DP0L		;DPL = DP0L @ AT89S8252
DPH		EQU	DP0H		;DPH = DP0H @ AT89S8252
BUFFER		EQU	30H		;byte buffer @ 30H int. RAM
CHAR_RCV_FLAG	BIT 	0		;character received Flag

		CSEG AT RESET		;
		ljmp START		;jump above interrupts

		CSEG AT RESET+23H	;serial interrupt @ address 0023H
		ljmp SER_INT		;UART ISR

		CSEG AT CODE_MEM_MAIN	;
START:		call INIT_DISPLAY	;initialize display
		call INIT_UART		;initialize UART
		
MAIN:		jnb char_rcv_flag,$	;do nothing till byte received Flag is set
		mov a,buffer		;read buffer
		cjne a,#24H,M1		;If a="$" then
		call cursor_home	;move cursor to the home position
		ljmp main		;loop
M1:		cjne a,#25H,M2		;else If a="%" then 
		call clear_display	;clear display
		ljmp main		;loop
M2:		cjne a,#26H,M3		;else If a="&" then
		mov a,#0A8H		;move cursor to the
		call enable		;2nd line
		ljmp main		;loop
M3:		call enable_data	;else write data to the display
		ljmp MAIN		;loop
		
;/// - UART ISR -

SER_INT:	push psw		;save psw
		push acc		;save acc
		push dpl		;save dpl
		push dph		;save dph
		jb ri,receive		;receiver interrupt ?
		jnb char_rcv_flag,ser_exit	;transmitter ready & no new char.
		mov sbuf,buffer		;send byte
		clr ti			;clear transmitter interrupt
		clr char_rcv_flag	;clr character received Flag
		sjmp ser_exit		;exit ISR
RECEIVE:	mov buffer,sbuf		;received byte into buffer
		clr ri			;clear receiver interrupt
		setb char_rcv_flag	;set Flag
SER_EXIT:	pop dph			;get dph 
		pop dpl			;get dpl 
		pop acc			;get acc 
		pop psw			;get psw 
		reti			;return from interrupt
		
;/// - initialize UART @ 38400 BAUD -

INIT_UART:	mov tmod,#20H		;timer MODE 1, 8 BIT auto reload
		mov th1,#0FDH		;timer preset for 38400 BAUD
		mov scon,#01011010B	;SM0=0 SM1=1 REN=1 TB8=1 RB8=1 TI=1
		mov pcon,#10000000B	;double BR_BIT=1 => @ 38400 BAUD
		setb tr1		;set timer RUN BIT
		setb es			;enable serial interrupt
		setb ea			;enable global interrupt
		clr char_rcv_flag	;clear character received Flag
		ret			;
		
;/// - initialize display
		
INIT_DISPLAY:	call wait_2		;wait 15 ms. after Power ON
		mov r1,#03H             ;3x38h
INITIALIZE:	mov a,#38H       	;set databus to 8 Bit
		call enable             ;entry mode inc. + shift
		call wait_0             ;wait 4.1 ms.
		djnz r1,initialize	;loop initialize 3x times
		mov a,#0DH	        ;cursor set to:
		call enable             ;off/on/blink = 0Ch/0Eh/0Dh
		call clear_display      ;clear display
		ret			;
		
;/// - display data transfer of control command -
		
ENABLE:		clr c			;serial instruction
		clr en			;enable = 0
		mov r7,#08h		;send 8 Bits
SERIOUT:	rlc a			;
		mov dd_bus,c		;data @ P2.0
		setb clk		;clock @ P2.4
		clr clk			;
		djnz r7,seriout		;
		clr dd_bus		;RS Bit = 0
		setb en			;enable @ P2.2
		clr en			;
		call wait_1		;
		ret			;
		
;/// - display data transfer of write data command -

ENABLE_DATA:	clr c			;serial data
		clr en			;enable = 0
		mov r7,#08h		;send 8 Bits
SERDOUT:	rlc a			;
		mov dd_bus,c		;data @ P2.0
		setb clk		;clock @ P2.4
		clr clk			;
		djnz r7,serdout		;
		setb dd_bus		;RS Bit = 1
		setb en			;enable
		clr en			;
		call wait_1		;
		ret			;
		
;/// - waitstates for display data & control commands -
				
WAIT_0:		mov r2,#0Fh     ;base clock 89S8252 22.118 MHz
		mov r0,#9Bh              ;init timing 3 cycles
WAIT__0:	djnz r0,wait__0          ;interval 4.1 ms
		djnz r2,wait__0          ;
		ret                      ;

WAIT_1:		mov r0,#24h              ;time for next display instruction
		djnz r0,$                ;42us.
		ret                      ;

WAIT_2:		mov r2,#36h              ;delay 15 ms.
		mov r0,#7Bh              ;after Power on
WAIT__2:	djnz r0,wait__2        	 ;
		djnz r2,wait__2          ;
		ret                      ;
		
;/// - display commands -

CURSOR_HOME:	mov a,#02h               ;cursor home
		call enable              ;
		call wait_0              ;
		ret                      ;

CLEAR_DISPLAY:	mov a,#01h               ;clear display
		call enable              ;
		call wait_0              ;
		ret                      ;

end


List of 31 messages in thread
TopicAuthorDate
help on serial communication            01/01/70 00:00      
   OK            01/01/70 00:00      
   Check this            01/01/70 00:00      
      Writing to SBUF            01/01/70 00:00      
         where?            01/01/70 00:00      
            Link            01/01/70 00:00      
               Where did he call it "tutorial" in his p            01/01/70 00:00      
         Loop back            01/01/70 00:00      
         SBUF            01/01/70 00:00      
         formally, yes            01/01/70 00:00      
   some books            01/01/70 00:00      
      A little more detail?            01/01/70 00:00      
         Andy, have a look at BOOKS on the left            01/01/70 00:00      
            If a poster assumes that everybody has            01/01/70 00:00      
               I have not read the books, but...            01/01/70 00:00      
               Yes, but            01/01/70 00:00      
   here we are            01/01/70 00:00      
      Tautology            01/01/70 00:00      
      Formatted            01/01/70 00:00      
      about code            01/01/70 00:00      
   about the code            01/01/70 00:00      
      push/pop in isr            01/01/70 00:00      
         the most often forgotten push/pop            01/01/70 00:00      
   hi            01/01/70 00:00      
   about the code            01/01/70 00:00      
      this can NOT be your question, elaborate            01/01/70 00:00      
         re: about the code            01/01/70 00:00      
            Serial EEPROM            01/01/70 00:00      
               Yes Jon            01/01/70 00:00      
               re more            01/01/70 00:00      
            sometimes the simple becomes complex            01/01/70 00:00      

Back to Subject List