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.

Mikropascal to ASM ?

Status
Not open for further replies.

seti75

New Member
hello
I can not seem to translate a program in mikroPascal asm program
the operation I want is the video, the program mikroPascal
it works very well in simulation.
question, how to have the same program in asm?
quelqun here can convert this program in mikroPascal asm?
thank you

video simulation program Mikropascal
https://www.youtube.com/watch?v=rnyvM3mGeUw

program mikropascal
program LEDINT;
var jeton, interuption: byte ;
i: integer;
procedure interrupt;
begin
interuption :=1;
portb.6:=0; /// SI INTERRUPTION RESET LED 1
portb.7:=0; /// SI INTERRUPTION RESET LED 2
portb.5:=1; /// SI INTERRUPTION LED DEFAUT
delay_ms(2000); ///
portb.5:=0; /// ON RESET LA LED DEFAUT
INTCON:=$90;
end;
Procedure attente;
begin
for i:=0 to 4000 do
begin
delay_ms(1);
if interuption = 1 then break;
end;
interuption :=0;
end;
begin
jeton:=0;
interuption:=0;
trisa.0:=1; ///SW1 EN ENTREE
trisa.1:=1; /// SW2 EN ENTREE
trisb.0:=1; /// INT EN ENTREE
trisb.6:=0; /// LED1 EN SORTIE
portb.6:=0; /// RESET LED1
trisb.7:=0; /// LED2 EN SORTIE
portb.7:=0; /// RESET LED2
trisb.5:=0; /// PORTB.5 EN SORTIE
portb.5:=0; /// LED DEFAUT RESET
INTCON:=$90;
while true do
begin
if ((porta.0 = 1) and ((jeton = 0) OR (jeton = 2))) then
begin
portb.6:=1;
jeton:=1;
attente;
portb.6:=0;
end;
if ((porta.1 = 1) and ((jeton = 0) OR (jeton = 1)))then
begin
portb.7:=1;
jeton:=2;
attente;
portb.7:=0;
end;
end;
end.
 
So far I've come up with this.... I kinda works but the interrupt is messing the operation up

I need some one with a fresh look
Code:
		list 	p=16f84a
		#include "p16f84a.inc"

jeton		equ 	0xC
inter		equ	0xD

wsav		equ	0xE
ssav		equ	0xF

count		equ	0x10
count1		equ	0x11
count2		equ	0x12
count3		equ	0x13
waitl		equ	0x14
waith		equ	0x15
isrdelay0	equ	0x16
isrdelay1	equ	0x17
isrdelay2	equ	0x18

		org	0
		goto	start
		org	4
		goto	ISR

start
		banksel	TRISA
		movlw	3
		movwf	TRISA
		movlw	1
		movwf	TRISB
		banksel	PORTB
		clrf	PORTB
		movlw	0x90
		movwf	INTCON	
		clrf	jeton
		clrf	inter	

loop		btfss	PORTA,0		
		goto	loop2
		btfsc	jeton,0
		goto	loop2	
		bsf	PORTB,6
		bsf	jeton,0
		bcf	jeton,1
		call	wait
		bcf	PORTB,6		

loop2		btfss	PORTA,1
		goto	loop
		btfsc	jeton,1
		goto	loop	
		bsf	PORTB,7
		bsf	jeton,1
		bcf	jeton,0
		call	wait
		bcf	PORTB,7
		goto 	loop	
	
wait		movlw	0x14
		movwf	waith
wait1		movlw	0xCB
		movwf	waitl
wait2		call	delay
		btfss	inter,0
		goto	wait3
		decfsz	waitl	
		goto	wait2
		decfsz	waith
		goto	wait1
		bcf	inter,0
wait3		return


ISR		movwf	wsav
		movf	STATUS,w
		movwf	ssav

		bsf	inter,0
		bcf	PORTB,6
		bcf	PORTB,7
		bsf	PORTB,5
		call	delay2000
		bcf	PORTB,5
		movlw	0x90
		movwf	INTCON

		movf	ssav,w
		movwf	STATUS	
		
		swapf	wsav,f
		swapf	wsav,w
		
		retfie

delay2000	movlw	0x10
		movwf	isrdelay2
		clrf	isrdelay1
		clrf	isrdelay0
d4		decfsz	isrdelay0
		goto	d4
		decfsz	isrdelay1
		goto	d4
		decfsz	isrdelay2
		goto	d4
		return	

delay		movlw	0x1
		movwf	count1
		clrf	count
d3		decfsz	count
		goto	d3
		decfsz	count1
		goto	d3
		return
end

some thing is messing with the delays when the interrupt is called *** Never mind !! It's working***

NOTE for those who think there is a problem there is waitl and a wait1 (slight difference)
 
Last edited:
Thanks, but this program does not work in simulation
operations research (ASM) is the video
 
I assemble with mpasmwin (5.36) , error 302, 205.305, and then build success ..
a simulation with isis nothing happens.
(4 MHz cristal)

(mplab ide 8.5)
 
Last edited:
very well, it works with your hex file.
but why can not I have the compiled ?
the point is to work then this file to add asm
several lines of program to edit it as needed
 
Hi seti75, MikroPascal will produce a .ASM file every time you compile your Pascal file. The file will have th esame name as your Pascal file (and be in the same directory) but will have the file extension .ASM or .LST.

So it is very easy to write small code segments in Pascal and then have them translated to ASM automatically. :)
 
Mr RB !! S75 doesn't have pascal only the old source file.... Anyway we're past that now ( he has been contacting me via PM ) he is re-writing for other functions.

I'll try and keep this post updated..
 
ok, I suggest to all my program

I could not have interrupted two times on RB0
I board create a disruption on PORTB (4 .. 5 .. 6 .. 7)
I want an interrupt on PORTB that lights a LED and that LED lights off then on PORTB should be able to detect a new a new interuption. I can only make a break.
works the first interruption and the LED lights off.
but after there is no detection interrupt ! ?... Why ? thank you
here is my program

sorry, reading in English must be complicated for you English friends
I would like -->
Here in "morse code" --> interrupt ---> led on -->2..3..seconds ...led off ! new interrupt ---> led on...---> 2...3..seconds...led off

(Currently, interrupt--> led on , no new interrupt)

list p=16f84A
#include p16f84A.inc
__Config _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC
;.............................................................




;******************** Variables utilisées ****************

var1 equ C
#define bphaut
#define bpbas
#define fchaut
#define fcbas


;********** Numero de version / données EEPROM ***********

ORG h'2100'
de "Version 1.0"

;************* definition des registres temporaires **********

retard1 EQU 0X0C ;le registre temporaire retard1 se trouve a l'adresse 0C
retard2 EQU 0X0F ;""""""""""""""""""""""""""""""""""""""""""""""""""""" 0F
retard3 EQU 0x10 ;""""""""""""""""""""""""""""""""""""""""""""""""""""" 0X10

;***************** Programme principal *******************

ORG 0
GOTO init

;*********** Sous Programme d 'interruption **********

ORG 4

;*********** IT sur RB4-RB7***********************************

bsf PORTA,0 ; on allume la led connectée sur ra0
call tempo
bcf INTCON,RBIF ; on raz le flag RBIF
bcf INTCON,RBIE
retfie ; retour d 'interruption


; *********** Programme d' INIT ***********************

init


bsf INTCON,GIE ; autorise les Interruptions
bsf INTCON,RBIE ; autorise l ' IT sur RB4-RB7
bsf STATUS,5 ; on met à 1 le 5eme bit du registre status pour accéder
; à la 2eme page mémoire ( pour trisa et trisb )
MOVLW B'11111100' ; programmation de rb0-rb7
MOVWF TRISB ; on met 11110000 dans le registre de direction du port B
MOVLW B'00110' ; programmation de ra0-ra4
MOVWF TRISA ; on met 00000 dans le registre de direction du port A
bcf STATUS,5 ; on remet à 0 le 5eme bit du registre status pour accéder
; à la 1eme page mémoire
clrf PORTA ; raz du port A
clrf PORTB ; raz du port B

end
 
Last edited:
Why have you turned off RBIE.....AND... where is your super loop....<- I don't think you get me.. You need to stop the program flow with a loop

ie...
goto -1..

or the program will crash


program flow...... setup ISR.... init....loop forever.. delay.

then call delay from the ISR
 
how I , loop forever ?

(interrupt led on....off....ok ---> bcf porta,0)
I can not make a second interupt.


list p=16f84A
#include p16f84A.inc
__Config _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC

;******************** Variables utilisées ****************

var1 equ C



;********** Numero de version / données EEPROM ***********

ORG h'2100'
de "Version 1.0"

;************* definition des registres temporaires **********

retard1 EQU 0X0C ;le registre temporaire retard1 se trouve a l'adresse 0C
retard2 EQU 0X0F ;""""""""""""""""""""""""""""""""""""""""""""""""""""" 0F
retard3 EQU 0x10 ;""""""""""""""""""""""""""""""""""""""""""""""""""""" 0X10

;***************** Programme principal *******************

ORG 0
GOTO init

;*********** Sous Programme d 'interruption **********

ORG 4

;*********** IT sur RB4-RB7***********************************

bsf PORTA,0 ; on allume la led connectée sur ra0
call tempo
bcf PORTA,0
bcf INTCON,RBIF ; on raz le flag RBIF
bcf INTCON,RBIE
retfie ; retour d 'interruption


; *********** Programme d' INIT ***********************

init


bsf INTCON,GIE ; autorise les Interruptions
bsf INTCON,RBIE ; autorise l ' IT sur RB4-RB7
bsf STATUS,5 ; on met à 1 le 5eme bit du registre status pour accéder
; à la 2eme page mémoire ( pour trisa et trisb )
MOVLW B'11111100' ; programmation de rb0-rb7
MOVWF TRISB ; on met 11110000 dans le registre de direction du port B
MOVLW B'00110' ; programmation de ra0-ra4
MOVWF TRISA ; on met 00000 dans le registre de direction du port A
bcf STATUS,5 ; on remet à 0 le 5eme bit du registre status pour accéder
; à la 1eme page mémoire
clrf PORTA ; raz du port A
clrf PORTB ; raz du port B

; ***************** Début de votre Programme ***********************



;****************** Programme de temporisation ***********************


; modifier les valeurs dans retard1 retard2 et retard3 pour changer la temporisation

tempo
MOVLW 0xFF ; on met ff dans le registre W (selon la tempo souhaitée)
MOVWF retard1 ; on met W dans le registre retard1
MOVWF retard2 ; on met W dans le registre retard2
MOVLW 0x12 ; on met 12 dans le registre W (selon la tempo souhaitée)
MOVWF retard3 ; on met W dans le registre retard3
attente
DECFSZ retard1,F ; on décrémente retard1 et on saute la prochaine instruction si
GOTO attente ; le registre retard1 = 0 sinon retour à attente
movlw 0xFF ; on recharge retard1 (selon la tempo souhaitée)
movwf retard1
DECFSZ retard2,F ; on décrémente retard2 et on saute la prochaine instruction si
GOTO attente ; le registre retard2 = 0 sinon retour à attente
movlw 0xFF ; on recharge retard2 (selon la tempo souhaitée)
movwf retard2
DECFSZ retard3,F ; on décrémente retard3 et on saute la prochaine instruction si
GOTO attente ; le registre retard3 = 0 sinon retour à attente
RETURN ; retour au programme principal après l 'instruction CALL

end ; fin du programme
 
Last edited:
list p=16f84A
#include p16f84A.inc
__Config _CP_OFF & _WDT_OFF & _PWRTE_ON & _HS_OSC

;******************** Variables utilisées ****************

var1 equ C



;********** Numero de version / données EEPROM ***********

ORG h'2100'
de "Version 1.0"

;************* definition des registres temporaires **********

retard1 EQU 0X0C ;le registre temporaire retard1 se trouve a l'adresse 0C
retard2 EQU 0X0F ;""""""""""""""""""""""""""""""""""""""""""""""""" """" 0F
retard3 EQU 0x10 ;""""""""""""""""""""""""""""""""""""""""""""""""" """" 0X10

;***************** Programme principal *******************

ORG 0
GOTO init

;*********** Sous Programme d 'interruption **********

ORG 4

;*********** IT sur RB4-RB7***********************************

bsf PORTA,0 ; on allume la led connectée sur ra0
call tempo
bcf PORTA,0
bcf INTCON,RBIF ; on raz le flag RBIF
bcf INTCON,RBIE
retfie ; retour d 'interruption


; *********** Programme d' INIT ***********************

init


bsf INTCON,GIE ; autorise les Interruptions
bsf INTCON,RBIE ; autorise l ' IT sur RB4-RB7
bsf STATUS,5 ; on met à 1 le 5eme bit du registre status pour accéder
; à la 2eme page mémoire ( pour trisa et trisb )
MOVLW B'11111100' ; programmation de rb0-rb7
MOVWF TRISB ; on met 11110000 dans le registre de direction du port B
MOVLW B'00110' ; programmation de ra0-ra4
MOVWF TRISA ; on met 00000 dans le registre de direction du port A
bcf STATUS,5 ; on remet à 0 le 5eme bit du registre status pour accéder
; à la 1eme page mémoire
clrf PORTA ; raz du port A
clrf PORTB ; raz du port B ; The program doesn't just stop here!!!

; ***************** Début de votre Programme ***********************

goto -1 ; you must stop it or it will go in to the tempo routine....Which has a return!!!!!

;****************** Programme de temporisation ***********************


; modifier les valeurs dans retard1 retard2 et retard3 pour changer la temporisation

tempo
MOVLW 0xFF ; on met ff dans le registre W (selon la tempo souhaitée)
MOVWF retard1 ; on met W dans le registre retard1
MOVWF retard2 ; on met W dans le registre retard2
MOVLW 0x12 ; on met 12 dans le registre W (selon la tempo souhaitée)
MOVWF retard3 ; on met W dans le registre retard3
attente
DECFSZ retard1,F ; on décrémente retard1 et on saute la prochaine instruction si
GOTO attente ; le registre retard1 = 0 sinon retour à attente
movlw 0xFF ; on recharge retard1 (selon la tempo souhaitée)
movwf retard1
DECFSZ retard2,F ; on décrémente retard2 et on saute la prochaine instruction si
GOTO attente ; le registre retard2 = 0 sinon retour à attente
movlw 0xFF ; on recharge retard2 (selon la tempo souhaitée)
movwf retard2
DECFSZ retard3,F ; on décrémente retard3 et on saute la prochaine instruction si
GOTO attente ; le registre retard3 = 0 sinon retour à attente
RETURN ; retour au programme principal après l 'instruction CALL

end ; fin du programme

Can you see what I mean
 
I do not understand, sorry.
by writing "goto", the interrupt program can be restarted again

(I started programming, I board not have much experience in programming asm)
 
Status
Not open for further replies.

Latest threads

Back
Top