Moving from PIC16F84A to Arduino UNO R3

Hi:


http://www.subeimagenes.com/img/router-zyxel-850073.png

Starting from this scheme is a PIC16F84A written in assembler and I want to pass it to C with Arduino UNO R3 . To be simple at first glance, I have eaten the head in 5 days to finish parts of the asm proque I forgot and had to practice and ask for help to the forum. Thanks collaborators . :slight_smile:

I'm not familiar in C on microcontrollers and I learn with tutorials, in my case I want to know their equivalence , and whoever wants to can help adapt the asm code to C. No need to know to pass it to C asm simply explain the circuit , maybe I shows faster than asm .

This is a micro PIC16F84A which has 5 buttons which when pressed in a fixed time delay is activated. A 12V DC motor output always works in the same direction or sense.

[b ] Key 1 = 5 minutes.
Button 2 = 10 minutes.
Button 3 = 20 minutes.
4 = Stop button .
Reset button 5 = PIC .
Each encensido Led corresponds to your switch . [/ b]

Its operation must be so because in the asm does not leave me .

By giving alilmentaci贸n source Arduino UNO R3 , motor and LED should be off. If I press the pulador P2 , ie , button 2, the DC motor is turned on for 10 minutes and Led 2 . If I press the button or not 1 when the 10 active minutes , simply count again from zero and takes 5 minutes activated motor. I hope you understand what I mean . The Pulsdor 4 is the Stop . If the motor is active and Led, Led stops engine and . The Reset resets the Arduino and coporta like the Stop button .

Here is the asm of 16F84A and hopefully help me pass it to C alkene have no idea , either compiled code, either .

;
;
; ZONA DE DATOS **********************************************************************

	LIST		P=16F84A聽 聽 聽 聽 ; Procesador.
	INCLUDE		<P16F84A.INC>聽  ; Definici贸n de las etiquetas del PIC.
	__CONFIG	_CP_OFF &聽 _WDT_OFF & _PWRTE_ON & _XT_OSC
聽 聽 __IDlOCS聽 聽 0001聽 聽 聽 聽 聽 聽 ; Versi贸n del programa.

Variables UDATA_SHR
RAM聽 聽  RES 1
RAM_1聽  RES 1
RAM_2聽  RES 1
RAM_3聽  RES 1
RAM_4聽  RES 1
RAM_5聽  RES 1
RAM_6聽  RES 1
RAM_7聽  RES 1
RAM_8聽  RES 1
RAM_9聽  RES 1
RAM_10聽 RES 1
RAM_11聽 RES 1
RAM_12聽 RES 1
RAM_13聽 RES 1
RAM_14聽 RES 1
RAM_15聽 RES 1
RAM_16聽 RES 1
RAM_17聽 RES 1

#DEFINE Pulsador_1	PORTA,4		; Pulsador conectado a RA4.
#DEFINE Pulsador_2聽 PORTA,3聽 聽  ; Pulsador conectado a RA3.
#DEFINE Pulsador_3聽 PORTA,2聽 聽  ; Pulsador conectado a RA2.
#DEFINE Pul_STOP聽 聽 PORTA,1聽 聽  ; Pulsador de parada del motor.
#DEFINE Motor		PORTB,7		; L铆nea donde se conecta el motor.
#DEFINE Led_1聽 聽 聽  PORTB,6聽 聽  ; Led 1.
#DEFINE Led_2聽 聽 聽  PORTB,5聽 聽  ; Led 2.
#DEFINE Led_3聽 聽 聽  PORTB,4聽 聽  ; Led 3.

; ZONA DE C脫DIGOS ********************************************************************

	ORG	0						; El programa comienza en la direcci贸n 0.
Inicio
 	bsf		STATUS,RP0			; Acceso al Banco 1.
	bsf		Pulsador_1			; La l铆nea RA4 se configura como entrada.
	bsf		Pulsador_2			; La l铆nea RA3 se configura como entrada.
	bsf		Pulsador_3			; La l铆nea RA2 se configura como entrada.
	bsf		Pul_STOP聽 聽 		; La l铆nea RA1 se configura como entrada.
	bcf		Motor				; Se configura como salida.
聽 聽 bcf聽 聽  Led_1聽 聽 聽 聽 聽 聽 聽  ; Led de aviso 5 minutos en activo.
聽 聽 bcf聽 聽  Led_2聽 聽 聽 聽 聽 聽 聽  ; Led de aviso 10 minutos en activo.
聽 聽 bcf聽 聽  Led_3聽 聽 聽 聽 聽 聽 聽  ; Led de aviso 20 minutos en activo.
	bcf		STATUS,RP0			; Acceso al Banco 0.
	bcf		Motor				; En principio Motor apagado igual
聽 聽 bcf聽 聽  Led_1聽 聽 聽 聽 聽 聽 聽  ; que los Leds.
聽 聽 bcf聽 聽  Led_2
聽 聽 bcf聽 聽  Led_3

Principal
	btfsc	Pulsador_1			; 驴Pulsador presionado?, 驴(Pulsador)=0?
	goto	Fin					; No. Vuelve a leerlo.
	call	Retardo20ms			; Espera que se estabilicen los niveles de tensi贸n.
	btfsc	Pulsador_1			; Comprueba si es un rebote.
	goto	Fin					; Era un rebote y sale fuera.
聽 聽 bsf聽 聽  Motor聽 聽 聽 聽 聽 聽 聽  ; Activa el motor y
聽 聽 bsf聽 聽  Led_1聽 聽 聽 聽 聽 聽 聽  ; enciende el Led 1 que significa
	call	Retardo5m聽 聽 聽 聽 聽 	; los 5 minutos encendido.
聽 聽 bcf聽 聽  Motor聽 聽 聽 聽 聽 聽 聽  ; Apaga el motor y
聽 聽 bcf聽 聽  Led_1聽 聽 聽 聽 聽 聽 聽  ; el Led 1.
EsperaDejePulsar_1
	btfss	Pulsador_1			; 驴Dej贸 de pulsar?. 驴(Pulsador)=1?
	goto	EsperaDejePulsar_1	; No. Espera que deje de pulsar.
Fin

	btfsc	Pulsador_2			; 驴Pulsador presionado?, 驴(Pulsador)=0?
	goto	Fin2				; No. Vuelve a leerlo.
	call	Retardo20ms			; Espera que se estabilicen los niveles de tensi贸n.
	btfsc	Pulsador_2			; Comprueba si es un rebote.
	goto	Fin2				; Era un rebote y sale fuera.
聽 聽 bsf聽 聽  Motor聽 聽 聽 聽 聽 聽 聽  ; Activa el motor y
聽 聽 bsf聽 聽  Led_2聽 聽 聽 聽 聽 聽 聽  ; enciende el Led 2 que significa
	call	Retardo10m聽 聽 聽 聽 聽 ; los 10 minutos encendido.
聽 聽 bcf聽 聽  Motor聽 聽 聽 聽 聽 聽 聽  ; Apaga el motor y
聽 聽 bcf聽 聽  Led_2聽 聽 聽 聽 聽 聽 聽  ; el Led 2.
EsperaDejePulsar_2
	btfss	Pulsador_2			; 驴Dej贸 de pulsar?. 驴(Pulsador)=1?
	goto	EsperaDejePulsar_2	; No. Espera que deje de pulsar.
Fin2

	btfsc	Pulsador_3			; 驴Pulsador presionado?, 驴(Pulsador)=0?
	goto	Fin3				; No. Vuelve a leerlo.
	call	Retardo20ms			; Espera que se estabilicen los niveles de tensi贸n.
	btfsc	Pulsador_3			; Comprueba si es un rebote.
	goto	Fin3				; Era un rebote y sale fuera.
聽 聽 bsf聽 聽  Motor聽 聽 聽 聽 聽 聽 聽  ; Activa el motor y
聽 聽 bsf聽 聽  Led_3聽 聽 聽 聽 聽 聽 聽  ; enciende el Led 3 que significa
	call	Retardo20m聽 聽 聽 聽 聽 ; los 10 minutos encendido.
聽 聽 bcf聽 聽  Motor聽 聽 聽 聽 聽 聽 聽  ; Apaga el motor y
聽 聽 bcf聽 聽  Led_3聽 聽 聽 聽 聽 聽 聽  ; el Led 3.
EsperaDejePulsar_3
	btfss	Pulsador_3			; 驴Dej贸 de pulsar?. 驴(Pulsador)=1?
	goto	EsperaDejePulsar_3	; No. Espera que deje de pulsar.
Fin3聽 聽 goto	Principal

; Subrutinas ****************************************************************

Retardo20ms
			;199993 cycles
	movlw	0x3E
	movwf	RAM_8
	movlw	0x9D
	movwf	RAM_9
Retardo20ms_0
	decfsz	RAM_8, f
	goto	$+2
	decfsz	RAM_9, f
	goto	Retardo20ms_0

			;3 cycles
	goto	$+1
	nop

			;4 cycles (including call)
	return

Retardo5m
			;299999995 cycles
	movlw	0x54
	movwf	RAM_10
	movlw	0xA1
	movwf	RAM_11
	movlw	0xFD
	movwf	RAM_12
	movlw	0x02
	movwf	RAM_13
Retardo5m_0
	decfsz	RAM_10, f
	goto	$+2
	decfsz	RAM_11, f
	goto	$+2
	decfsz	RAM_12, f
	goto	$+2
	decfsz	RAM_13, f
	goto	Retardo5m_0

			;1 cycle
	nop

			;4 cycles (including call)
	return

Retardo10m
			;599999992 cycles
	movlw	0xA9
	movwf	RAM_4
	movlw	0x41
	movwf	RAM_5
	movlw	0xFA
	movwf	RAM_6
	movlw	0x04
	movwf	RAM_7
Retardo10m_0
	decfsz	RAM_4, f
	goto	$+2
	decfsz	RAM_5, f
	goto	$+2
	decfsz	RAM_6, f
	goto	$+2
	decfsz	RAM_7, f
	goto	Retardo10m_0

			;4 cycles
	goto	$+1
	goto	$+1

			;4 cycles (including call)
	return

	cblock
	RAM
	RAM_1
	RAM_2
	RAM_3
	endc

Retardo20m
			;1199999995 cycles
	movlw	0x54
	movwf	RAM_14
	movlw	0x82
	movwf	RAM_15
	movlw	0xF3
	movwf	RAM_16
	movlw	0x08
	movwf	RAM_17
Retardo20m_0
	decfsz	RAM_14, f
	goto	$+2
	decfsz	RAM_15, f
	goto	$+2
	decfsz	RAM_16, f
	goto	$+2
	decfsz	RAM_17, f
	goto	Retardo20m_0

			;1 cycle
	nop

			;4 cycles (including call)
	return

	END

Encouragement and forth. Then I have what I eestudiar the code to analyze and understand the concept.

Greeting.

Hello again:

The Arduino sketch is done. Just need programming.


http://www.subeimagenes.com/img/arduino-motor-dc-bb-850766.png

Any tips?

A greeting.

Untested but maybe something simple like this...

#define btn5Min 2
#define btn10Min 3
#define btn20Min 4
#define btnStop 5

#define led5Min 10
#define led10Min 11
#define led20Min 12

#define motor 13

#define debounceDelay 20

unsigned long offTime = 0;聽 聽 // Time to turn motor off

void setup(){
聽 pinMode(btn5Min,INPUT_PULLUP);聽 聽 // Define button pins as input
聽 pinMode(btn10Min,INPUT_PULLUP);
聽 pinMode(btn20Min,INPUT_PULLUP);
聽 pinMode(btnStop,INPUT_PULLUP);
聽 
聽 ledsOff();
聽 pinMode(led5Min,OUTPUT);聽 聽 聽 聽 聽 // pins default to input so should not be needed but for compleatness
聽 pinMode(led10Min,OUTPUT);
聽 pinMode(led20Min,OUTPUT);
聽 
聽 digitalWrite(motor,LOW);聽 聽 聽 聽 聽 // Turn motor off
聽 pinMode(motor,OUTPUT);
}

void loop(){
聽 if(checkButton(btn5Min) == LOW){
聽 聽 offTime = millis() + (300 * 1000);聽 // 300 seconds
聽 聽 ledsOff();
聽 聽 digitalWrite(led5Min,HIGH);
聽 聽 digitalWrite(motor,HIGH);聽 聽 聽 聽 聽  // Turn motor on
聽 }
聽 if(checkButton(btn10Min) == LOW){
聽 聽 offTime = millis() + (600 * 1000);聽 // 600 seconds
聽 聽 ledsOff();
聽 聽 digitalWrite(led10Min,HIGH);
聽 聽 digitalWrite(motor,HIGH);聽 聽 聽 聽 聽  // Turn motor on
聽 }
聽 if(checkButton(btn20Min) == LOW){
聽 聽 offTime = millis() + (1200 * 1000); // 1200 seconds
聽 聽 ledsOff();
聽 聽 digitalWrite(led20Min,HIGH);
聽 聽 digitalWrite(motor,HIGH);聽 聽 聽 聽 聽  // Turn motor on
聽 }
聽 if(checkButton(btnStop) == LOW){
聽 聽 offTime = millis();聽 聽 聽 聽 聽 聽 聽 聽  // Stop now
聽 }
聽 
聽 if(millis() > offTime){
聽 聽 ledsOff();
聽 聽 digitalWrite(motor,LOW);聽 聽 聽 聽 聽 // Turn motor off
聽 }
}

void ledsOff(){
聽 digitalWrite(led5Min,LOW);聽 聽 聽 聽 // Turn LED's off
聽 digitalWrite(led10Min,LOW);
聽 digitalWrite(led20Min,LOW);
}

// Button = pin number to read
byte checkButton(byte Button){
聽 byte buttonState = digitalRead(Button);聽 聽 聽 聽 聽 聽  // Read button
聽 if (buttonState == LOW){聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 // If button pressed then wait a bit to allow for debounce
聽 聽 unsigned long Time = millis(); 
聽 聽 while ((millis() - Time) < debounceDelay){聽 聽 
聽 聽 }
聽 聽 buttonState = digitalRead(Button);聽 聽 聽 聽 聽 聽 聽 聽 // Read button again
聽 聽 return buttonState;聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽  // Return button state
聽 }
聽 else {聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 // Button not pressed so no need to wait for bebounce
聽 聽 return HIGH;
聽 }
}

EDIT: Updated to turn other leds off when button pressed.

Any tips?

Yes have a common ground connection between you 12V supply and the arduino or it won't work.

The Arduino sketch is done.

The arduino sketch is the program, what you have is a physical layout diagram.

Hello:

Thank you very much. I thought you have to use this command.
http://arduino.cc/en/Reference/SwitchCase#.UwS7hoVw7G1

As difetente two voltages and ground. It is the same power source.

I'll try the code and upload their pictures and videos.

Muchas gracias. :wink:

I updated the code as I realized it did not turn off other leds when a button was pressed.

New scheme.

View scheme.

A speaker or piezoelectric buzzer is used. The output pins of Arduino UNO R3, you decide. I will test the new code.

Thank you very much.