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.

Help with code please

Status
Not open for further replies.

Magen

New Member
Hello everybody,
I am trying to write code to send data serially to a shift register (74HC595). I have been able to do this but my pgm does not exit from 'Shiftdata' (see attached code) Can anybody help me with this please? I am using a 16F628A,
RA0 for data, RA1 for Clk , RA2 for Latch and RA3 for OutputEnable.

Any help is appreciated.
 

Attachments

  • 74HC595.asm
    2.9 KB · Views: 159
Hello everybody,
I am trying to write code to send data serially to a shift register (74HC595). I have been able to do this but my pgm does not exit from 'Shiftdata' (see attached code) Can anybody help me with this please? I am using a 16F628A,
RA0 for data, RA1 for Clk , RA2 for Latch and RA3 for OutputEnable.

Any help is appreciated.

hi,
Its stuck in the delay loop.

Check the 'del' subr , where are the two, 20 and 21 registers..?
 
Hi Eric,
Txs for the reply. I don't understand your question. Are you asking why I haven't loaded these 2 registers B4 calling Del? I, as part of testing held the Latch and OE pins on the 595 at the needed levels and found that the outputs of the 595 are changing (cycling as expected) so I think the Del routine is working. My problem showed up when I added the BitHi routine. Is there any other way to send data serially? This is my first serial project.
 
Last edited:
What Eric was talking about was this section of code:
Code:
Del	    	NOP
			DECFSZ [COLOR="Red"]20[/COLOR],1
			GOTO Del
			DECFSZ [COLOR="Red"]21[/COLOR],1
			GOTO Del
			RETURN
You could be accessing invalid memory locations in this routine because 20 in DECIMAL is 0x14 in Hex which is an unimplemented memory location if the default radix of the compiler is set to decimal! You really should use labels for your variables and use the PIC include file to make things clearer and easier to fix/debug:

Code:
#include <p16f628.inc>        ; processor specific variable definitions
	cblock 0x20
        temp1
        temp2
        endc

Del	       DECFSZ temp1,F
		GOTO Del
		DECFSZ temp2,F
		GOTO Del
		RETURN
 
Last edited:
Txs Kchriste,
I didn't see that. You're correct, my coding needs some work:)

hi magen,
Your original program with a few changes to the labels, just a simple example on how to use the include and labels.

When you use the include, you dont need to redefine the ports etc.

Also be consistent with the way you type in the variables..
eg: your using 20, 20h 0x20 etc.

Which assembler are you using.?:)
 

Attachments

  • 74HC595a.asm
    2.4 KB · Views: 148
Hi Eric,
I'm using MPLAB V8.00 . I don't know if it's something I'm doing wrong, but if I type MOVLW xxh , I cannot enter a value greater than 9F. If I enter the value as 0xCF for eg. the compiler seem happy. I don't get any errors when compiling but if I enter CFh , the colour of the text (purple instead of blue)indicates that the compiler does not accept this value.:confused:

I was very eager to get the project working so I didn't spend as much time as I should have on good coding practice. I'll post a pic later of what I did.
Txs for the help:)
 
Hi Eric,
I'm using MPLAB V8.00 . I don't know if it's something I'm doing wrong, but if I type MOVLW xxh , I cannot enter a value greater than 9F. If I enter the value as 0xCF for eg. the compiler seem happy. I don't get any errors when compiling but if I enter CFh , the colour of the text (purple instead of blue)indicates that the compiler does not accept this value.:confused:

I was very eager to get the project working so I didn't spend as much time as I should have on good coding practice. I'll post a pic later of what I did.
Txs for the help:)

hi,
If the first digit in the hex value is greater than 9, say A thru F you must place a "0" in front..

eg:: movlw 0CFh
or use 0xCF

OK.?:)
 
Figured that. But why? Is this specific to MPLAB or something in general?

hi,
Its a general thing, it was done originally so that assembler could distinguish
between text/label and a number.

eg: CFH could be seen as a label [name] by the assembler
but no label [name] should begin with a zero "0".....;)
 
Hi
This is what I managed to do so far. The idea is to eventually make a 7 x 30 message display but I'm really happy to have gotten this far.

Sorry about the pic quality:(
 

Attachments

  • 20072008(002).jpg
    20072008(002).jpg
    174 KB · Views: 140
Hi
This is what I managed to do so far. The idea is to eventually make a 7 x 30 message display but I'm really happy to have gotten this far.

Sorry about the pic quality:(

hi,
Thats pretty good for starters..:)

When you have the 7 * 30 working, post an image.

EDITED: Mon21st... EditingTest for ElectroMaster.
 
Last edited:
Txs
I'm not totally a beginner though. I studied a little bit of electronics a long time ago so the assembly language and electronics isn't all new to me. Hope to have the 7 * 30 up and running soon but still have to get familiar with EEPROM, I2C etc
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top