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.

[SOLVED] Help on this Assemblt code!

Status
Not open for further replies.

vishy71

Full Member level 2
Joined
Dec 16, 2010
Messages
126
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
Iran
Activity points
2,296
hi there! i really need to now why this code is not right!because in PIC simulator ide and protues it can't work!

processor p16f84a
include <p16f84a.inc>
__config _WDT_OFF & _CP_OFF & _XT_OSC & _PWRTE_OFF
org 0x00
goto peykar
org 0x04
goto check
peykar
bsf STATUS,5
movlw 0x80
movwf OPTION_REG
clrf TRISB
bcf STATUS,5
clrf PORTB
movlw 0xA0
movwf INTCON

main
bsf PORTB,1
goto $-1

check
bcf PORTB,1
bcf INTCON,2
bsf INTCON,7
end

it say :hardware stack overflow!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
heeeeeeeeeeeeeeeeeeeeeeelp me!
i will very happy if you send me an email to know you have answer my question
thanks
 

Hi,

Looks like you are trying to flash a led on RB1 - and basically it is doing that, but so fast you cannot see it - you need a Delay between turning the port on and off.

See this good assembler tutorial on how to do it.

PIC Tutorial One - LED's
 
  • Like
Reactions: vishy71

    vishy71

    Points: 2
    Helpful Answer Positive Rating
the program is looping around main
Code:
	processor p16f84a
	include <p16f84a.inc>
	__config _WDT_OFF & _CP_OFF & _XT_OSC & _PWRTE_OFF
	org 0x00
	goto peykar
	org 0x04
	goto check
peykar
	bsf STATUS,5
	movlw 0x80
	movwf OPTION_REG
	clrf TRISB
	bcf STATUS,5
	clrf PORTB
	movlw 0xA0
	movwf INTCON

[B]main
	bsf PORTB,1
	goto $-1[/B]
	
check
	bcf PORTB,1
	bcf INTCON,2
	bsf INTCON,7
	
	end
 
vishy71,

The program structure seems be wrong.
The main funcion is generally called at ORG vector ( 0x00 ).
Try rename simultaneously all ocurrences of peykar by main.
 
thanks! but i want to check interrupt not make falsh on RB1!
can labels name effect on program! oh sorry my english is not very good i don't know can i give you my mean or no!

in fact i wanna use interrupts and this is a small and easy example for me and my friends! but it dosen't work! peykar means body in english!it's persian name!
well can you write this program in other code?

thank you very much
 

thanks! but i want to check interrupt not make falsh on RB1!
can labels name effect on program! oh sorry my english is not very good i don't know can i give you my mean or no!

in fact i wanna use interrupts and this is a small and easy example for me and my friends! but it dosen't work! peykar means body in english!it's persian name!
well can you write this program in other code?

thank you very much
generally between ORG 0x00 and ORG 0x04 they wont add lines
while perhaps some one can write, but won't help us learn
so better read the datasheet,
and software manual that helps write interrupt using techniques.

Best of luck
 
  • Like
Reactions: vishy71

    vishy71

    Points: 2
    Helpful Answer Positive Rating
Hi,

The interrupt can be a bit difficult to get in to, while you have coded to set up for an interrupt to occur, you have not made proper provision for when the interrupt does occur.

When it does the program jumps to the ISR. Inerrupt Service Routine, located on your chip at 0x04 ( thats why after org 00x00 it always Jumps to the Main part of your program code to avoid going into the ISR )

Every Microchip has a Template file, a simple bit of starter code, located in Mplab/MPasm /template/code/ 16F84A.asm
Thats shows the basic ISR coding and an important thing called context Saving, so the pic does not loose its place in the main program code when jumping the ISR.

Also look at AN566 from Microchip which explains how to do external interrupts.
http:
//ww1.microchip.com/downloads/en/AppNotes/00566b.pdf


Edit - when in the ISR keep within it, do not goto or call to code that is not within the ISR, if needed set a flag for use later in the main code.
Basically if you do jump out of the ISR it can get lost and crash.
 
Last edited:
thanks

i will try youre idea and may i use other ways to now interrupt!

i have another question that i will realy happy if you answer!
i can find to use LCD with assembly!but most of them were for 8 wire data connection can you help me to use LCD in 4 wire and say what command will like if we use lcd with 4 line data bus?

thanks

---------- Post added at 23:15 ---------- Previous post was at 23:13 ----------

thanks but you address dosen't right! whould you mind to change it please?
 

i have another question that i will realy happy if you answer!
i can find to use LCD with assembly!but most of them were for 8 wire data connection can you help me to use LCD in 4 wire and say what command will like if we use lcd with 4 line data bus?

Hi,

If you see this very good and well proven tutorial it has a detailed LCD example, have not used that exact method myself though.
It should convert to the 84A chip without much trouble, athough like the ISR it can sometimes be difficult for the beginner to get running ok.
PIC Tutorial* Three - LCD Modules
That whole series of tutorials are good but I think he has over complicated the ADC section by introducing op amps and voltage references at the very beginning.


For a very detailed explanation of lcd with code examples see here.
EPE FAQs & Resources


thanks but you address dosen't right! whould you mind to change it please?

Sorry, but just not sure what you mean here ..?:?
 
  • Like
Reactions: vishy71

    vishy71

    Points: 2
    Helpful Answer Positive Rating
hi

i mean the address https://ww1.microchip.com/downloads/en/AppNotes/00566b.pdf
the file is not found!

---------- Post added at 12:06 ---------- Previous post was at 11:40 ----------

hi there! I change my interrupt code! this code work good but i must check T0IF and i can't automatically know intterrupt!
this is new code:

processor p16f84a
include <p16f84a.inc>
__config _WDT_OFF & _CP_OFF & _PWRTE_OFF & _XT_OSC
clrf TMR0
movlw b'00100000'
movwf INTCON
bsf STATUS,5
movlw b'10001000'
movwf OPTION_REG
clrf TRISB
bcf STATUS,5
goto main

main
bsf PORTB,0
btfss 0x0b,2
goto $-2
goto interrupt

interrupt
bcf PORTB,0
bcf INTCON,2
nop
nop
goto main
end


whould you mind to say what is .95 or other number like this?for example see this code please:


movlw .173
movwf Reg_1
movlw .19
movwf Reg_2
movlw .6

why he/she use .19 not 19 or .6 not 6?i mixed up!
myyyyyyyyyyyyyyyyyyyy english is not very good but your forum may be forced me to learn more and more!
thaaaaaaaaaaaaaaaaaaaaaaaaanks
 

Hi,

Well that link works ok from here ..?
Just Google ' AN566 ' and it should take you to that pdf on the Microchip site or goto the Microchip site and search on AN566

It should answer all your questions on RB0 interrupts and how it loops /checks for an interrupt occurring.

I have taken the Mplab template file and quicky inserted your program code.
You might be able to see how the ISR is a seperate section from your main code.
It builds ok, but I have not looked at your code to check it in detail.

Regarding the numbering system - well as you know the computers work in simple binary, but for programmers to code everything in binary would be a difficult job.
Over the years people have developed different ways of representing the binary code in an easier form, the main ones in use with Pics are Hexadecimal, Ascii, Decimal and still some Binary.

In Mplab there is a setting for selecting the default numbering system to be used during your project - the RADIX.
You can also specify the RADIX at the beginning of your code to override MPlabs project default. See Projects/ Build Options/ Assembler

I tend to code with Hex as the default Radix and specify the other numbers as below.

Hex is default but I still actually code the hex number as 0xFF rather than just FF, you will also see it coded as hFF.

For decimal .19 or d19 are used

Binary b'00000000' usefull for setting Ports and maths.


I might have time later to seach out a working 4 bit lcd routine for you as its a difficult thing for the beginner to get work, - unless you want to try coding it for yourself first ?
Are you using a 4 mhz crystal for the oscillator on your 16F84A ? - need to know as the lcd routine uses Delay routines based on the crystals speed.
 
  • Like
Reactions: vishy71

    vishy71

    Points: 2
    Helpful Answer Positive Rating
hi

than you very much! I am really happy to find your site!it's really good site!
thanks for you time to answer my questions!

well yeah i wanna use 4 bit lcd!but if you have time to find and if you find!
thanks for every thing!

---------- Post added at 19:59 ---------- Previous post was at 18:10 ----------

hi there!
i find my wrong!i don't use retfie and i write bsf INTCON,7!after my code programe jump to label that micro was not doing that!but with retfie interrupt enable again and program continue were interrupt was happen!

can u understand my mean?
:-(
sorry!english-english-english!

our country is really weak in education!
 

hi

than you very much! I am really happy to find your site!it's really good site!
thanks for you time to answer my questions!

well yeah i wanna use 4 bit lcd!but if you ave time to find and if you find!
thanks for every thing!


Hi,


The attached LCD rar file contains the hex code and dsn so you can run the simulation.
It also contain a folder with the full MPlab project so you can quicky see the code and play around with it and change the messages.

It also has a jpeg of the full circuit is you want to actually build the hardware.
You can use a 2x16 or 2x20 lcd with this code, a 4x16 or 4x20 is possible with a little modification - just ensure you use a Hitachi HD44780 compatible type.


hi there!
i find my wrong!i don't use retfie and i write bsf INTCON,7!after my code programe jump to label that micro was not doing that!but with retfie interrupt enable again and program continue were interrupt was happen!

can u understand my mean?

Not quite, but if you post the code you are having trouble with I will probably follow what you mean.

Don't worry about the English - at least you can use another language - thats one more than me !;-)
 

Attachments

  • Vishy.rar
    99.4 KB · Views: 106
  • Like
Reactions: vishy71

    vishy71

    Points: 2
    Helpful Answer Positive Rating
hi
thanks for every thing.
this is my new code :

processor p16f84a
include <p16f84a.inc>
__config _WDT_OFF & _CP_OFF & _PWRTE_OFF & _XT_OSC

org 0
goto body

org 4
bcf INTCON,2
bcf PORTB,0
call setRB1
retfie

body
clrf TMR0
movlw b'10100000'
movwf INTCON
bsf STATUS,5
movlw b'10001000'
movwf OPTION_REG
clrf TRISB
bcf STATUS,5
goto main

setRB1
bsf 0x06,1
return

main
bsf PORTB,0
goto $-1

end

it work with any errors!

alse thanks for Vishy.rar

I made a robot to play football! writting program was Proton or mikroC or Basic but any of them can't answer my question!
i understand Assembly is the best compiler than any other one!so i really wanna to learn it!

---------- Post added at 10:16 ---------- Previous post was at 08:59 ----------

Hi

I see you LCD project.thanks
but can you say what's th banksel instruction please?

wow! it really hard!
i hope one day i can use these instruction as myself! let me say it perisan:
امیدوارم یه روزی بتونم خودم این دستورات رو بنویسم!

you can translate it in google!
I wish you be happy in all times of your life
 

Hi,

Glad to see you have got your Interrupt code working ok, do not be afraid to put lots of comments by your instructions, although you know what it is doing now, in a few months time you may look back and wonder what that code was doing !

The Banksel TrisA etc. is a simple way to change register memory banks rather that the usual BSF STATUS RP0 etc.

Banksel is not an Instruction but a Directive - assembler uses a lot of them such as ORG and CBLOCK - the difference is basically Instructions are coverted into op codes / hex but directives simply tell MPASMs complier what to do.
You can find full details of them in the Micochip Assembly User Manual.

Don't worry about trying to understand the detail of the lcd program its a difficult routine.
Just learn to use it to load and send out your messages to the lcd, its so much better to see the results on a screen.

Everyone finds their own way to learn programming, Assembler does really teach you about the hardware and software but eventually will limit you when it comes to the big projects like USB etc which do mean moving to C.

Enjoy your programming....
 
  • Like
Reactions: vishy71

    vishy71

    Points: 2
    Helpful Answer Positive Rating
you say right!in big project i must learn C!
thanks for every thing.
I hope understatnd assembly beacause with it i can understatnd every thing.
one day i will go to learn PIC C
but now I bealive assembly is important.thanks for every thing and your time
hope happy for you and wish winner in the life for you
 

Hi,

Just looked at your code in more detail and saw it looked wrong.

Have done a working example for you - attached.

Important things, you must use the Context Saving code when using the ISR.
Do not use a Call out of the ISR routine.
If you do not do the above then when it has finished the ISR it may loose its way or some data when trying to go back to the main program loop


You do not have to use Interrupts to test for a port being on - you also can 'poll' the port from your main program loop
 

Attachments

  • interrupt.rar
    12.2 KB · Views: 95
  • Like
Reactions: vishy71

    vishy71

    Points: 2
    Helpful Answer Positive Rating
Hi
but swapf f,d means (if d=0) w=w-f! what's your mean about swapf STATUS,0?

at the frist time,some registers are clear!like status or intcon or PCLATH and...! why do you clear then?
i think it can be like this:


ORG 0x000
goto start

ORG 0x004 ; Interupt Service Routine with Context Save


servint movwf w_temp ; copy W to temp
swapf STATUS,W ; swap status to be saved into W
clrf STATUS ; bank 0
movwf status_temp ; save status in bank O

; your ISR code goes here

bcf INTCON,INTF ; RBO has interrupted to now clear its Flag
bsf PORTA,0 ; turn on the LED


swapf status_temp,W ; swap status temp to w to set org bank
movwf STATUS ; movW to status
swapf w_temp,F ; restore W
swapf w_temp,W

retfie ; return from isr

do we have to write this bold instructions?

---------- Post added at 21:30 ---------- Previous post was at 21:28 ----------

oh I forget! what's you mean about movwf w_temp in servint label please?
is any thing in the W register to copy it in w_temp register?
thanks
 

Hi,

Just take a quick look at your simple code.

I notice your "check" routine which is an ISR didn't have retfie after bsf INTCON,7 which is before the end of code section.
Insert the "retfie" should solve the hardware stack overflow problem.

You have to careful of read-modify-write action of bcf or bsf instruction since now you have they both in interrupt and main routine to act on portB. It would be best to have a shadow register and have main update to PORTB based on shadow register result.

Regards,
Tom
 
  • Like
Reactions: vishy71

    vishy71

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top