Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

GLCD assembler code

Status
Not open for further replies.
You can try and make some sense of this,
Code:
Plot		call	SetLCDAddress
		clrf	Mask
		movfw	YPos
		andlw	0x07
		movwf	Count
		bsf	STATUS,C
GetBit		rlf	Mask,F
		decf	Count,F
		btfss	Count,7
		goto	GetBit
		call	ReadData	;dummy read
		call	ReadData
		iorwf	Mask,F
		movfw	XPos
		andlw	0x3f
		iorlw	0x40
		call	WriteCMD
		movfw	Mask
		call	WriteData
		return

Cls_1		bsf	b_LCD_CS1
		bsf	b_LCD_CS2
		movlw	0x08
		movwf	ForI
ClsLoopI	movlw	0x40
		movwf	ForJ
		call	WriteCMD
		decf	ForI,W
		iorlw	0xb8
		call	WriteCMD
ClsLoopK	movlw	0x00		
		call	WriteData
		decfsz	ForJ,F
		goto	ClsLoopK
		decfsz	ForI,F
		goto	ClsLoopI
		clrf	XPos
		clrf	YPos
		return

InitLCD_1	bsf	b_LCD_CS1
		bsf	b_LCD_CS2
		movlw	0x3f
		call	WriteCMD
		movlw	0xc0
		call	WriteCMD
		movlw	0x40
		call	WriteCMD
		movlw	0xb8
		call	WriteCMD
		return

WaitNotBusy	bsf	STATUS,RP0
		movlw	0xff
		movwf	TRISB
		bcf	STATUS,RP0
		bsf	b_LCD_RW
		bcf	b_LCD_RS  
		btfss	b_LCD_CS1
		goto	Skip_CS1
		bcf	b_CS2
		btfsc	b_LCD_CS2
		bsf	b_CS2
		bcf	b_LCD_CS2
WNB1_Loop	bsf	b_LCD_E
		btfsc	PORTB,7
		goto	WNB1_Loop
		bcf	b_LCD_E
		btfsc	b_CS2
		bsf	b_LCD_CS2
Skip_CS1	btfss	b_LCD_CS2
		goto	Skip_CS2
		bcf	b_CS1
		btfsc	b_LCD_CS1
		bsf	b_CS1
		bcf	b_LCD_CS1
WNB2_Loop	bsf	b_LCD_E
		btfsc	PORTB,7
		goto	WNB2_Loop
		bcf	b_LCD_E
		btfsc	b_CS1
		bsf	b_LCD_CS1
Skip_CS2	bsf	STATUS,RP0
		clrf	TRISB
		bcf	STATUS,RP0
		return

ReadLCD		bsf	b_LCD_E
		movfw	PORTB
		bcf	b_LCD_E
		btfsc	b_Inverted
		xorlw	0xff
		return

WriteCMD	movwf	LCDTemp
		call	WaitNotBusy
		movfw	LCDTemp
		movwf	PORTB
		bcf	b_LCD_RW
		bcf	b_LCD_RS
		bsf	b_LCD_E
		bcf	b_LCD_E
		return

WriteData	movwf	LCDTemp
		call	WaitNotBusy
		movfw	LCDTemp
		btfsc	b_Inverted
		xorlw	0xff
		movwf	PORTB
		bcf	b_LCD_RW
		bsf	b_LCD_RS	;rs=1 rw=0
		bsf	b_LCD_E
		bcf	b_LCD_E
		return

ReadData	call	WaitNotBusy
		bsf	STATUS,RP0
		movlw	0xff
		movwf	TRISB
		bcf	STATUS,RP0
		bsf	b_LCD_RW
		bsf	b_LCD_RS
		bsf	b_LCD_E
		movfw	PORTB
		bcf	b_LCD_E
		btfsc	b_Inverted
		xorlw	0xff
		bsf	STATUS,RP0
		clrf	TRISB
		bcf	STATUS,RP0
		return

SetLCDAddress	bcf	b_LCD_CS1
		bcf	b_LCD_CS2
		btfss	XPos,6
		bsf	b_LCD_CS1
		btfsc	XPos,6
		bsf	b_LCD_CS2
		movfw	XPos
		andlw	0x3f
		iorlw	0x40
		call	WriteCMD
		movfw	YPos
		movwf	Row
		rrf	Row,F
		rrf	Row,F
		rrf	Row,F
		movfw	Row
		andlw	0x7
		iorlw	0xb8
		goto	WriteCMD

A few notes on the above code,
It's written for 16F886.
The TRIS registers need setting up.
It does everything inverted, cls fills the screen with ones and plot clears the bits.
The WaitNotBusy routine checks the CS bits to decide which side of the display to check. It may check both. It leaves the state of CS1/2 unchanged.
All variables starting b_ are bit variables - do,
Code:
#define		b_CS1		Flags,0
#define		b_CS2		Flags,1
#define		b_Inverted	Flags,2
#define		b_Font		Flags,3
#define		b_Fixed		Flags,4
#define		b_LineWidth	Flags,5

#define		b_LCD_CS1	PORTA,2
#define		b_LCD_CS2	PORTA,3
#define		b_LCD_RS	PORTC,5
#define		b_LCD_RW	PORTC,0
#define		b_LCD_E		PORTC,2

Sorry for the lack of comments.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top