Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Need example for cyclic buffer in 8051

Status
Not open for further replies.

nannchee

Newbie level 3
Joined
Nov 12, 2010
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,302
I 'need an example for cyclic buffer in 8051 microcontroller ..


Thanks
 

your statment is not clear,
pl. write what exactly you want.what do you mean by cyclic buffer.

cyclic buffers are used usually in serial communication and sometimes with interrupt concepts..

Downloads / Examples / Serial Circular buffer example : 8051 Microcontroller Projects AVR PIC Projects Tutorials Ebooks Libraries codes

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:
;;;;;;;;;;;;;;;;
PUSH ACC
JNB RI,TMT
CLR RI
MOV A,SBUF
LCALL WRITE_BUF
LJMP EXIT1
TMT: CLR TI
EXIT1: POP ACC
RETI
;;;;;;;;;;;;;;;;
WRITE_BUF:
;;;;;;;;;;;;;;;;
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
INC R1
LCALL DELAY
LCALL SERIAL_OUT ;BOUNCE BACK
EXIT2: RET
;;;;;;;;;;;;;;;;
SERIAL_OUT:
;;;;;;;;;;;;;;;;
MOV SBUF,A
RET
;;;;;;;;;;;;;;;;
DELAY:
;;;;;;;;;;;;;;;;
MOV R3,#250
RPT: NOP
NOP
DJNZ R3,RPT
RET
;;;;;;;;;;;;;;;;
MAIN:
;;;;;;;;;;;;;;;;
MOV R0,#START ; 'WRITE' POINTER
MOV R1,#START ; 'READ' POINTER
LCALL SERIAL_INIT
AGAIN: LCALL SERIAL_READ
LJMP AGAIN
END
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top