CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug Reports on this forum. Send them to support@ccsinfo.com

PIC Assembler 16F872 LCD 2x16 Hitachi Clocking

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Regular Guy



Joined: 04 Jun 2017
Posts: 102

View user's profile Send private message

PIC Assembler 16F872 LCD 2x16 Hitachi Clocking
PostPosted: Sat Jun 19, 2021 11:07 am     Reply with quote

Why do we have to 'Clock' it?

Here is Clock subroutine.

Thanks!

Code:
CLOCK BSF PORTA,2
NOP
BCF PORTA,2
NOP
RETLW 0

_________________
CCS 16F1459 PCWH Compiler

CCS 18F14K50 PCWH Compiler

ICD-U40

ICD-S40

Embedded Serial Busses Development Kit

dsPIC30F4012 Development Kit

16F877 Development Kit


Last edited by Regular Guy on Sun Jun 20, 2021 11:16 am; edited 1 time in total
Regular Guy



Joined: 04 Jun 2017
Posts: 102

View user's profile Send private message

PostPosted: Sat Jun 19, 2021 11:40 am     Reply with quote

Here is Clock used in 'Display Configuration'.

Code:
;Display Configuration
MOVLW 03H ;FUNCTION SET
MOVWF PORTB ;8bit data (default)
CALL CLOCK
CALL DELAYP1 ;wait for display
MOVLW 02H ;FUNCTION SET
MOVWF PORTB ;change to 4bit
CALL CLOCK ;clock in data
CALL DELAYP1 ;wait for display
MOVLW 02H ;FUNCTION SET
MOVWF PORTB ;must repeat command
CALL CLOCK ;clock in data
CALL DELAYP1 ;wait for display
MOVLW 08H ;4 bit micro
MOVWF PORTB ;using 2 line display.
CALL CLOCK ;clock in data
CALL DELAYP1
MOVLW 0H ;Display on, cursor off
MOVWF PORTB ;0CH
CALL CLOCK
MOVLW 0CH
MOVWF PORTB
CALL CLOCK



NOTE:Code loses formatting when we use 'Code' here.

It is copied from .PDF book NOT MPLAB program.
_________________
CCS 16F1459 PCWH Compiler

CCS 18F14K50 PCWH Compiler

ICD-U40

ICD-S40

Embedded Serial Busses Development Kit

dsPIC30F4012 Development Kit

16F877 Development Kit
Regular Guy



Joined: 04 Jun 2017
Posts: 102

View user's profile Send private message

PostPosted: Sat Jun 19, 2021 11:45 am     Reply with quote

Here is explanation for it from book.

Quote:
This data is then clocked into the display by pulsing the Enable line, (E, A2
on the micro) high and then low with:
CLOCK BSF PORTA,2
NOP
BCF PORTA,2
NOP
RETLW 0


Guess we can go with that.

Does seem to still be a question 'Why do you have to do it?'

Thanks.
_________________
CCS 16F1459 PCWH Compiler

CCS 18F14K50 PCWH Compiler

ICD-U40

ICD-S40

Embedded Serial Busses Development Kit

dsPIC30F4012 Development Kit

16F877 Development Kit
Jerson



Joined: 31 Jul 2009
Posts: 106
Location: Bombay, India

View user's profile Send private message Visit poster's website

PostPosted: Sat Jun 19, 2021 9:25 pm     Reply with quote

Simple explanation I can suggest

Since the data bus on which your commands are being sent out could also be used for other devices, the data that needs to go to the LCD needs to pass through a gate. This gate is opened and closed by the clock pulse. This keeps the LCD sane.
Ttelmah



Joined: 11 Mar 2010
Posts: 17477

View user's profile Send private message

PostPosted: Sun Jun 20, 2021 1:14 am     Reply with quote

However the point is that this could be done just as well in C as assembler.
CLOCK here is a label, so the 'name' that the function is given.

In MPASM, a 'Label', _must_ start in column 1, and _may_ be followed by a
colon.
So 'CLOCK' is the name of this function.

So the function can be called with:

CALL CLOCK

If you have PORTB as a #byte, then the C:
Code:

void clock(void)
{
   bit_set(PORTB,2);
   delay_cycles(1);
   bit_clear(PORTB,2);
   delay_cycles(1);
}

Performs the same operations.
Regular Guy



Joined: 04 Jun 2017
Posts: 102

View user's profile Send private message

PostPosted: Sun Jun 20, 2021 11:13 am     Reply with quote

Thank you Jerson

Simple works for us.

Thank you Ttelmah

Right now we must stay with assembler.
_________________
CCS 16F1459 PCWH Compiler

CCS 18F14K50 PCWH Compiler

ICD-U40

ICD-S40

Embedded Serial Busses Development Kit

dsPIC30F4012 Development Kit

16F877 Development Kit
temtronic



Joined: 01 Jul 2010
Posts: 8220
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jun 20, 2021 4:21 pm     Reply with quote

curious am I ...

this...

Quote:
This data is then clocked into the display by pulsing the Enable line, (E, A2
on the micro) high and then low with:
CLOCK BSF PORTA,2
NOP
BCF PORTA,2
NOP
RETLW 0

...

I have to wonder what the RETLW 0 code is for ?
Regular Guy



Joined: 04 Jun 2017
Posts: 102

View user's profile Send private message

PostPosted: Sun Jun 20, 2021 7:32 pm     Reply with quote

Thank you temtronic

Here is 'definition' for RETLW in back of book.

Section in back of book is author's 'definition's' for instructions.

PIC In Practice David W Smith

Quote:
RETLW This instruction is used at the end of a subroutine to return to the
program following a CALL instruction. The literal value is
placed in the W register. This instruction can also be used with a
look up table.
E.g. RETLW 0

_________________
CCS 16F1459 PCWH Compiler

CCS 18F14K50 PCWH Compiler

ICD-U40

ICD-S40

Embedded Serial Busses Development Kit

dsPIC30F4012 Development Kit

16F877 Development Kit
temtronic



Joined: 01 Jul 2010
Posts: 8220
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jun 20, 2021 7:43 pm     Reply with quote

I do know what the instruction does, been 'playing with PICs' long before CCS C came out.., but don't know why it's there.

portion of code...
Code:
;Display Configuration
MOVLW 03H ;FUNCTION SET
MOVWF PORTB ;8bit data (default)
CALL CLOCK
CALL DELAYP1 ;wait for display
MOVLW 02H ;FUNCTION SET
MOVWF PORTB ;change to 4bit
CALL CLOCK ;clock in data

... doesn't use the contents of W after the CALL CLOCK..
Ttelmah



Joined: 11 Mar 2010
Posts: 17477

View user's profile Send private message

PostPosted: Sun Jun 20, 2021 11:20 pm     Reply with quote

You would have to look at what DELAYP1 does. This might be using W.
However RETLW takes no more time than a RETURN, and does therefore
provide a 'zero cost' way of clearing W, so the programmer may have
just got into the habit of using this.
Regular Guy



Joined: 04 Jun 2017
Posts: 102

View user's profile Send private message

PostPosted: Mon Jun 21, 2021 9:46 am     Reply with quote

Thank you Ttelmah

Ah hah!

It is a COMBINATION instruction.

A RETURN and a MOVLW

Literal being loaded to or into W is 0

Very sharp catching that and pointing it out.

We had just laid it off to it was a 'Good Practices' thing.

Never really thought about it much though.

Thanks!

EDIT:

We caught two things you said

1 'No Cost' thing to do

2 Clears W register

Yes. low cost is good and clearing registers does play into things.

Cleared registers can reduce 'Erratic behavior' and 'Unexpected Results'

and straight out bugs.
_________________
CCS 16F1459 PCWH Compiler

CCS 18F14K50 PCWH Compiler

ICD-U40

ICD-S40

Embedded Serial Busses Development Kit

dsPIC30F4012 Development Kit

16F877 Development Kit
Ttelmah



Joined: 11 Mar 2010
Posts: 17477

View user's profile Send private message

PostPosted: Mon Jun 21, 2021 10:17 am     Reply with quote

Though (of course), you have to be aware that the effect can be
adverse.
Assume you have a code sequence that sets W up with something before
the routine, then the programmer looks at the functions 'inside' the
subroutine, and thinks "bit sets, nops, so no change to W", but misses
the RETLW. Result W is not what is expected.... Sad
The RETLW is very commonly used in CCS for the more basic PIC's
as a way of storing const values. You just have a sequence of these
for all the values, and in front of this, have code that just adds the
entry number required to the PC. Call this, and it returns with the required
value. On PIC's that don't have any way to directly read their ROM,
this is the only way to do this...
Regular Guy



Joined: 04 Jun 2017
Posts: 102

View user's profile Send private message

PostPosted: Mon Jun 21, 2021 10:29 am     Reply with quote

Thank you Ttelmah

Most of what you say is ahead of what we are doing.

BUT

There is a 7 Segment LED lesson in the book

It has a 'Lookup Table' . For each number.As you would think.

That may be a little of what you are talking about.

Let me post the RETLW part of 7 segment program.

Code:
The look up table for this is:
CONVERT ADDWF PC
RETLW B’01110111’ ;0
RETLW B’01000001’ ;1
RETLW B’00111011’ ;2
RETLW B’01101011’ ;3
RETLW B’01001101’ ;4
RETLW B’01101110’ ;5
RETLW B’01111100’ ;6
RETLW B’01000011’ ;7
RETLW B’01111111’ ;8
RETLW B’01001111’ ;9


Quote:
The look up table for this is:
CONVERT ADDWF PC
RETLW B’01110111’ ;0
RETLW B’01000001’ ;1
RETLW B’00111011’ ;2
RETLW B’01101011’ ;3
RETLW B’01001101’ ;4
RETLW B’01101110’ ;5
RETLW B’01111100’ ;6
RETLW B’01000011’ ;7
RETLW B’01111111’ ;8
RETLW B’01001111’ ;9


Pasting .PDF loses the formatting no matter if we use CODE or QUOTE
_________________
CCS 16F1459 PCWH Compiler

CCS 18F14K50 PCWH Compiler

ICD-U40

ICD-S40

Embedded Serial Busses Development Kit

dsPIC30F4012 Development Kit

16F877 Development Kit
Ttelmah



Joined: 11 Mar 2010
Posts: 17477

View user's profile Send private message

PostPosted: Tue Jun 22, 2021 12:03 am     Reply with quote

Yes, that is doing exactly this. Using the RETLW instructions as a way
to give a lookup from ROM.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group