PIC16F684 Digital Thermometer

Status
Not open for further replies.

me_guitarist

Full Member level 6
Joined
Oct 3, 2006
Messages
338
Helped
0
Reputation
0
Reaction score
0
Trophy points
16
Location
Malaysia
Activity points
0
pic16f684

Can Somebody convert this code to assembly language?
I can't understand the C language so pls help.Thanks!

Code:
#include <pic.h>

#define	DIGIT1	RA0	
#define	DIGIT2	RA1	
#define 	DIGIT3	RA2	
#define	ON			0
#define	OFF		1

/* 
RA5 - Segment a
RC5 - Segment b
RC4 - Segment c
RC3 - Segment d
RC2 - Segment e
RC1 - Segment f
RC0 - Segment g

RA4 - Thermistor
*/

__CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT \
  & UNPROTECT & BORDIS & IESODIS & FCMDIS);
  
  
const char LEDDigit[10] = {
    0b0000001,                  //  Digit Zero
    0b1001111,                  //  Digit One
    0b0010010,                  //  Digit Two
    0b0000110,                  //  Digit Three
    0b1001100,                  //  Digit Four
    0b0100100,                  //  Digit Five
    0b0100000,                  //  Digit Six
    0b0001111,                  //  Digit Seven
    0b0000000,                  //  Digit Eight
    0b0000100};                 //  Digit Nine
    
  
int Temperature, TempDigit, DisplayPos, D1, j;
int ADCState;

int i, j, d, t, temp;
main()
{
	///////////  INIT  ////////////
	
	PORTA = 0;
	PORTC = 0;
	TRISA = 0b010000;      		//  All Bits of PORTA are Outputs except RA4
   TRISC = 0;           		//  All Bits of PORTC are Outputs
   
   CMCON0 = 7;                //  Turn off Comparators
   ANSEL = 1 << 4;            //  RA4 is ADC input
   ADCON0 = 0b00001101;			//  Left justify, Use Vdd, Channel 4 (AN3), Do not start, Turn on
   ADCON1 = 0b00010000;			//  run oscillatr as 8 x prescalar
   
   DisplayPos = 0;
   j = 0;
   Temperature = 0;
   ADCState = 0;

  
   ////  MAIN LOOP  ////
   
   while(1)
   {
	   ///////////  DISPLAY READOUT  ///////////
	   
	   DIGIT1 = OFF;
	   DIGIT2 = OFF;
	   DIGIT3 = OFF;
	   
		if(DisplayPos == 0)									//Light 1st segment
		{
			TempDigit = Temperature % 10;					//Just get "1"s place
			RA5 = LEDDigit[TempDigit] >> 6;				//Turn on digit
			PORTC = LEDDigit[TempDigit];
			DIGIT3 = ON;
			for(D1=0;D1<414;D1++);							//Delay for 7ms
			
		}else if(DisplayPos == 1)							//Light 2nd segment
		{
			TempDigit = Temperature % 100;				//Just get "10"s place (strip off "100"s place)
			TempDigit = TempDigit / 10;					//   and convert to "1"s place
			RA5 = LEDDigit[TempDigit] >> 6;				//Turn on digit
			PORTC = LEDDigit[TempDigit];
			DIGIT2 = ON;
			for(D1=0;D1<400;D1++);							//Delay for 7ms
		}else														//Light 3rd segment
		{	
			TempDigit = Temperature / 100;				//Just get "100"s place
			RA5 = LEDDigit[TempDigit] >> 6;				//Turn on digit
			PORTC = LEDDigit[TempDigit];
			DIGIT1 = ON;
			for(D1=0;D1<400;D1++);							//Delay for 7ms
		}

		DisplayPos = (DisplayPos + 1) % 3;				//Next segment
		
		
		j++;
		if(j == 50)												//Time to update temp?
		{
			j = 0;
		
			switch(ADCState)
			{
				case 0:						//Start ADC operation
					GODONE = 1;
					ADCState = 1;
					break;
				case 1:
					ADCState = 0;
					Temperature = ADRESH - 82;
					break;
			}
		}
	}
}
 

pic16f684 temperature

Hi,

Why do you have to have that exact code in assembler ?

Its just a simple adc reading and a lookup table to convert the result to 7 segment output - shouldn't be too hard to code in assembler - have you tried ? - if you have and got stuck then post your code so we can offer some help.
 

pic 16f684 application

Hi wp100,

thanks for yr input. I can't understand a single code in C language.

now I found Gooligum Electronics tutorial very useful.
I'll be trying on assembly. (it have both assembly & C language).
 

asm code for a digital thermometer

Hi,

If you are just starting out on assembler try this tutorial - it covers ADC etc and the code should work on your chip with only the odd change.
The guy who wrote it is still contactable and its known to be a good course.

http://www.winpicprog.co.uk/pic_tutorial.htm
 

pic16f684 #include main()


Thanks wp100
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…