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 for change source code to PIC assembly language

Status
Not open for further replies.

tobble

New Member
there is the PIC 16F84 heart beat calculation source code i take from one of the thread, can someone help me to translate to the PIC assembly language, thank !

___________________________________________________________________________

#include<htc.h>

#define _XTAL_FREQ 32768 //Specifies oscillator frequency of 32.768 Khz

char beat_rate=0,med,time=0; //Variable declaration and intialization

//This array defines the decimal equivalents for setting the output pins in driving the 7 segment displays.
char num[10]= {126, //0
12, //1
182, //2
158, //3
204, //4
218, //5
250, //6
14, //7
254, //8
222 //9
};

//This function is called every time an interrupt occurs
void interrupt intrpt(void){

if(INTF==1){ //This is true if the interrupt was caused by a rising edge on RB0
beat_rate++; //Increment the pulse count
INTF=0; //Reset the external interrupt flag
}//end if(INTF==1)

if(T0IF==1){ //This is true if the interrupt was caused by a TMR0 overflow
time++; //Increment the interrupt counter
if(time==60){ //This is true every 60th TMR0 overflow (once per minute)
time=0; //Reset interrupt counter
T0CS=1; //Sets the T0CKI as the external clock source for TMR0
INTCON=0; //Disables all interrupts
}//end if(time==60)
}//end if(T0IF==1)

}//end intrpt()

//This function is called to drive the 7 segment displays
void show(){

med=beat_rate/100; //calculates the 100's digit
PORTB=num[med]; //Assigns result to PORTB
RA2=0;__delay_ms(10); //Enable digit 3; delay long enough for digit to be seen
RA2=1; //Disable digit 3

med=(beat_rate%100)/10; //Calculates the 10's digit
PORTB=num[med]; //Assigns result to PORTB
RA1=0;__delay_ms(10); //Enable digit 2; delay long enough for digit to be seen
RA1=1; //Disable digit 2

med=beat_rate%10; //Calulcates the 1's digit
PORTB=num[med]; //Assigns result to PORTB
RA0=0;__delay_ms(10); //Enable digit 1; delay long enough for digit to be seen
RA0=1; //Disable digit 1

}//end show()

void main ( ){

TRISA=0b11111000; //Set bits 0-2 as output and bits 3-7 as input
TRISB=0b00000001; //Set bit 0 and input and bits 1-7 as output
PORTA=0b00000111; //Sets bits 0-2 and clears bits 3-7
TMR0=0; //Clears the TMR0 register
OPTION=0b11100100; //Sets TMR0 options and pre-scaler
INTCON=0; //Clears the INTCON register

//main program loop
while(1){

start:

while(RA3==1){ //If pushbutton is pressed
show();
}

beat_rate=0;
T0CS=0; //Set the internal instruction clock as the clock source for TMR0
INTCON=0b10110000; //Globally enables interrupts, TMR0 interrupt, and RB0 external interrupt

while(T0IE==1){ //If TMR0 interrupt is enabled
show();
}

INTCON=0; //Disables all interrupts

while(beat_rate!=0){
show();
if(RA3==0){ //If pushbutton is not pressed
__delay_ms(125); //Delays for 125 ms
__delay_ms(125); //Delays for 125 ms
TMR0=0; //Clears the TMR0 register
beat_rate=0;
goto start;
}
}

}//END while (1)

}//End main

//___________END_PROGRAM___________
 
Hi,

Doubt anyone will recode a complete project like that for you - why don't you simply compile the code you have and then program that hex file.
 
Well,first of all, why would you need the code in assembly if its working in C? if you still want assembly, then check out the dis assembly listing, its present in all compilers, but i should inform you its a pain to to go through it since you will find a lot of extra information.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top