;----------------------------------------------------------------------------------------; ;THIS PROGRAM IMPLEMENTS A CYCLIC BUFFER ON THE SERIAL PORT(RECEIVED DATA) ; ;MEMORY POINTERS ARE STORED IN THE REGISTERS R0&R1(STARTING ADDRESS IS 20H) ; ;BUFFER LENGTH IS 20H TO 30H LOCATION ; ;BUFFER SIZE CAN BE VARIED ACCORDING TO YOUR REQUIREMENT AND SIZE OF RAM ; ;----------------------------------------------------------------------------------------; ;This code is written by Mubashar Yasin(Islamabad,Pakistan).It is freely distributable ; ;however please distribute it with my name and if you add this code to your website or ; ;some other publication then mention about me along with this code.I have tested this ; ;code to work properly even then there is no guarantee or warranty and i cannot be held ; ;responsible for any damage or loss due to this code.If you have any querries about this ; ;code please contact me at: ; ; ; ; kool_projects@yahoo.com ; ; mubasharpk09@hotmail.com ; ; ; ;or visit my website: ; ; ; ; http://www.geocities.com/kool_projects ; ;----------------------------------------------------------------------------------------; START EQU 20H ORG 0000H LJMP MAIN ORG 0023H LJMP SERIAL_ISR ;;;;;;;;;;;;;;;; SERIAL_INIT: ;;;;;;;;;;;;;;;; MOV SCON,#52H ;8-BIT UART,REN MOV TMOD,#20H ;8-BIT AUTO RELOAD MODE MOV TH1,#-3 ;9600 BPS AUTO RELOAD VALUE SETB EA ;GLOBAL INTERRUPT ENABLE SETB ES ;SERIAL INTERRUPT ENABLE SETB PS ;HIGH PRIORITY FOR SERIAL INTERRUPTS SETB TR1 ;START TIMER RET ;;;;;;;;;;;;;;;; SERIAL_ISR: ;;;;;;;;;;;;;;;; JNB RI,TMT CLR RI MOV A,SBUF LCALL C_BUFFER LJMP EXIT1 TMT: CLR TI EXIT1: RETI ;;;;;;;;;;;;;;;; C_BUFFER: ;;;;;;;;;;;;;;;; CJNE R0,#31H,NEXT1 ;CHECK FOR BUFFER RECYCLE MOV R0,#20H ;CYCLE AGAIN NEXT1: MOV @R0,A INC R0 RET ;;;;;;;;;;;;;;;; SERIAL_READ: ;;;;;;;;;;;;;;;; MOV A,R0 MOV B,R1 CJNE A,B,NEXT2 ;COMPARE R0 & R1 LJMP EXIT2 ;NOTHING TO READ(BUFFER EMPTY) NEXT2: CJNE R1,#31H,NEXT3 MOV R1,#20H ;JUMP TO START (RECYCLE) NEXT3: MOV A,@R1 MOV R2,A INC R1 EXIT2: RET ;;;;;;;;;;;;;;;; MAIN: ;;;;;;;;;;;;;;;; MOV R0,#START ;WRITE POINTER MOV R1,#START ;READ POINTER LCALL SERIAL_INIT AGAIN: LCALL SERIAL_READ LJMP AGAIN END