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

Back to Subject List

Thread Closed: Issue successfully resolved

???
03/11/04 16:26
Read: times


 
#66522 - Serial comm interrupt driven Done
This is to inform all participants of 66485 thread
http://www.8052.com/forum/rea...&top=66485

that I have succeeded in my task of having serial interrupt driven communication
The asm code is posted on the link below and also at the end of this post
http://www.ikraft.biz/netbaba/p...serpat.txt

any one could use it but without removal of auhors name

I thank erik , Patrik ,Hans and others for helping me out

Sorry Webmaster : I thought it is important to inform everyone that their help worked.
As my original thread as mentioned above was closed at my request and only after that was I able to get my script right I had to create a new post

I would appreciate if you could add this post as the 61st post of the original thread so a knowledge base exists.


The script


;Program: SERIAL TRANSMISSION USING INTERRUPT
;Author :Kashyap Deepak Email: netbaba@indiatimes.com
;Website:http://www.ikraft.biz/netbaba/
;Script website :http://www.ikraft.biz/netbaba/p...serpat.txt
;This program is sends a 'OK' on the terminal screen of the pc when there is a request from PC
;to transmit using control letter 'S' , S stands for request status
;I am using LF and CR for the same to put charachters on separate lines
;A transmit buffer is created from 40h onwards
;R0 is used as a transmit buffer pointer.
;R1 as a counter
;A lot of discussion has gone into making it work you can see it in the link below ( Thanks 8052.com)
;Also Thanks erik , Patrik ,Hans and others for helping me out
;http://www.8052.com/forum/rea...&top=66485
;----------------------------------------
;License : You are free to use this script without removing the header as above ,Thank you


$mod51


ORG 0000H ;Origin address
LJMP MAIN ; Jump to intialisation
ORG 0023H ;Serial interupt
LJMP SERIAL

ORG 30H
;****************************************************************
;Main program starts here with all necessary initialisations *
;The program starts from 0000h *
;Jumps to a location MAIN *
;Initializes stack to 60h *
;Makes P1 an input port by moving FF into the port *
;TMOD sets timer 1 in 8bit auto reload *
;Set baud rate to 9600 bps *
;Scon set to 8 bit data mode with 1 start and stop bit and receive disabled *
;Global interrupt, serial interrupt enable *
;LED at p1.0 switched on indicate working of the controller *
;Start timer 1 *
;Move hex equivalent of ‘O’ into a memory location 40h *
;Move hex equivalent of ‘K’ into a memory location 41h *
;Also load line feed (0Ah) & carriage return (0D) to 42h & 43h respectively *
;www.asciitables.com to view a ASCII control char with their hex code *
;The pointer value of 40 is loaded into transmit pointer r0 *
;****************************************************************

MAIN: MOV SP,#60H ; To avoid stack from beign overwritten we reset stack to 60H
MOV P1,#0FFH ;Make P1 input port
MOV TMOD,#20H ; Timer1 8 bit auto reload Timer0 16 bit timer mode
MOV TH1,#0FDH ;Set TH1 for 9600 bps@11.0592MHz
MOV SCON,#50H ;8 bit data mode with 1 start and stop bit and receive enable
MOV IE,#90H ;Global interrupt, serial interrupt enable
CLR P1.0 ; LED at p1.0 switched on
SETB TR1 ; Start timer for serial transmission
CLR TI ;Clear TI flag

;*********Start Filling transmit buffer****************

MOV 40h,#'O'
MOV 41h,#'K'
MOV 42h,#0Ah
MOV 43h,#0dh

;*********End Filling transmit buffer****************

LOOP:SJMP LOOP

;-----------------END OF MAIN------------------------

;----Start of Serial ISR ----------------------------------
ORG 100H

;***********|****************************************************************************************
;STAGE 1 |
;----------------
;On serial interrupt at 0023h we analyse if TI or RI was set,then clear the respective flag and execute program
;according to FLAG condition
;*****************************************************************************************************
;IF RI is set
;Move content of A to SBUF and check for three consditions
; If letter 'S' was tranmitted
; Load transmit buffer pointer (TBP) to 40h ( starting of TB) into R0
; Load transmit counter in R1 with 04h
; Indicate visually operation by LED sate change
; Move content pointed by TBP to A
; Send it to SBUF for transmission to PC
; Once transmission takes place in this stage The TI Flag is set again and hence stage 2 of operations take place
; ( explained later)
; If the transmitted char was 'O' P1.0 pin is cleared and LED Glows and RETI is executed
; If the transmitted char was 'S' P1.0 pin is cleared and LED switches OFF and RETI is executed

;*******************************************************************************************************

SERIAL: JB TI,CLEAR
MOV A,SBUF
CLR RI
CJNE A,#'S',RET_OPEN
MOV R0,#40h
MOV R1,#04h
CPL P1.0
CLR A
MOV 21h,#1h ;A Flag bit for future development
MOV A,@R0 ;Move content pointed by R0 into A
MOV SBUF,A ;Move content pointed by A into SBUF
SJMP RET_END

RET_OPEN:CJNE A,#'O',RET_CLOSE
CLR P1.0 ; Switches ON led connected to P1.0

RET_CLOSE:CJNE A,#'C',RET_END
SETB P1.0 ; Switches OFF led connected to P1.0

RET_END:RETI

;***********|************************************************************
;STAGE 2 |
;----------------
;If TI Flag is set
;Due to Previous Transmission of Letter 'O' to terminal Screen TI flag is set
;Now the counter R1 is decremented and and checked if it is not equal to zero it jumps to NEXT
;Else RETI is executed.
;On jumping to NEXT R0 is incremented to point to next location 41h
;Visually indicate with LED
;Move content pointed by TBP to A
;Send it to SBUF for transmission to PC
:Again this transmission sets TI flag
;And again stage 2 is execute for locations 42h and 43h
;**********************************************************************
CLEAR: CLR TI

DJNZ R1,NEXT
RETI
NEXT:INC R0
CPL P1.0
CLR A
MOV A, @R0
MOV SBUF,A
RETI

;----End of Serial ISR ---------------------------------
END

List of 8 messages in thread
TopicAuthorDate
Serial comm interrupt driven Done            01/01/70 00:00      
   RE: Serial comm interrupt driven Done            01/01/70 00:00      
   RE: Serial comm interrupt driven Done            01/01/70 00:00      
      RE: Serial comm interrupt driven Done            01/01/70 00:00      
   RE: Serial comm interrupt driven Done            01/01/70 00:00      
   RE: Serial comm interrupt driven Done            01/01/70 00:00      
      RE: Serial comm interrupt driven Done            01/01/70 00:00      
      RE: Serial comm interrupt driven Done            01/01/70 00:00      

Back to Subject List