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.

Auto-increment Puzzle

Status
Not open for further replies.

jpanhalt

Well-Known Member
Most Helpful Member
Progress has been slow with learning to manipulate bits on the NHD-12864MZ GLCD, which is KS0108 based. MCU= PIC16F1519 at 8 MHz.

Note, the most current datasheet has the pin assignments for CS1 and CS2 reversed. Pin 12 is CS1 and Pin 13 is CS2.

Before getting to my question, let me say that I take no credit for these code segments. They were kindly provided by Pommie, except for a few edits by me.. One thing to be aware of is he refers to the horizontal axis as the X-axis, and the Y-axis is vertical. Those labels are rotated from the labels used by NHD and other display manufacturers. I have kept that orientation as it seems much more natural. Therefore "Pages" are on the Y-axis and auto-incrementing is along the X-axis.

My question has to deal with making auto-incrementing on the X-axis work to give the expected image.

Following are two examples of code. The first example ("Not Work") sets up a counter in "WriteDupData" to write the same data across the screen in sequential X positions. In this case 6 instances. The data is the binary b'01011010'. When used with Pommie's "WriteData" for a single instance, it appears on the vertical exactly as expected. When written with the "WriteDupData" code, it appears as b'01100010' at the correct location and with the correct length (I'm drawing lines of a sort.).

The second example of code ("Works") in which both X and Y axes are set works fine. In that code I take care of incrementing the XPos value in "LCDMain".

I can't understand what is happening to the data in the auto-increment mode. Any ideas? I have been struggling with it for more than 2 days.

Regards, John

Code:
;*******************************************************************************      
                         
LCD_Main                 
                Call    LoadXY          ;NB:Conventional XY as used by Pommie
                Call    SetLCDAddress   ;
                Call    LoadData        ;loads LCD temp & sets invert flag
                Call    WriteDupData
                                        ;Call WriteData   
                goto    LCD_Power
                         
LoadXY                   
                movlw   0x44            ;bit<6> = 1,CS1|0=CS2 b'01001000'
                movwf   XPOS            ;bits<5:0> = column 0x48
                movlw   0x0F            ;bits<5:3> = page bits<2:0> = count
                movwf   YPOS            ;0x27 = b'00100111'=page4
                return                  ;0x37 = b'00110111'=page6
                                        ;0x0F = page1   
LoadData                 
                bcf     b_inverted      ;b_inverted = 0 = not inverted
                movlw   0x5A            ;0xD5 =b'11010101'
                movwf   LCDTemp         ;0x5A =b'01011010'
                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   
                         
WriteDupData             
                movlw   d'6'            ;replicates to test autoadvance
                movwf   Count
XLoop_count              
                Call    SetLCD_Y
                Call    WriteData
                decfsz  Count,f         ;added for duplicates
                goto    XLoop_count     ;added for duplicates
                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   
                         
WaitNotBusy              
                DelayCy (50*usecs)
                         
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
                         
SetLCD_Y                 
                movfw   YPos
                movwf   Row
                rrf     Row,F
                rrf     Row,F
                rrf     Row,F
                movfw   Row
                andlw   0x07
                iorlw   0xb8
                goto    WriteCMD

Code:
;*******************************************************************************  
                        
LCD_Main                
                call    LoadXY          ;NB:Conventional XY as used by Pommie
                variable X=0
                while   x<6
                incf    XPos,f
                call    SetLCDAddress
                call    LoadData
                call    WriteData
x=x+1                   
                endw    
                goto    LCD_Power
                        
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
                        
WaitNotBusy             
                DelayCy (50*usecs)
                        
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
SetLCD_Y                
                movfw   YPos
                movwf   Row
                rrf     Row,F
                rrf     Row,F
                rrf     Row,F
                movfw   Row
                andlw   0x07
                iorlw   0xb8
                goto    WriteCMD
                        
LoadXY                  
                movlw   0x44            ;bit<6> = 1,CS1|0=CS2 b'01001000'
                movwf   XPOS            ;bits<5:0> = column 0x48
                movlw   0x0F            ;bits<5:3> = page bits<2:0> = count
                movwf   YPOS            ;0x27 = b'00100111'=page4
                return                  ;0x37 = b'00110111'=page6
                                        ;0x0F = page1 
LoadData                
                bcf     b_inverted      ;b_inverted = 0 = not inverted
                movlw   0x5A            ;0xD5 =b'11010101'
                movwf   LCDTemp         ;0x5A =b'01011010'
                return
 
Last edited:
Found it! :eek:

I had lost track of w, aggravated by not enough sleep and a little dyslexia (movfw vs. movwf look the same to me so many times). Maybe I should start using movf.

Here is the corrected critical segment:
Code:
WriteData
		call	WaitNotBusy
		call	LoadData
		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
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top