Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a PICmicro Assembly code that does the following: Accepts temperature in C

ID: 2246947 • Letter: W

Question

Write a PICmicro Assembly code that does the following: Accepts temperature in Centigrade ranging from 0 to 127 oC on Port A. Output the temperature in Fahrenheit ranging from 1 to 126 on Port B. "O" output represent too low to show temperature and "127" represents too high to show. Every hour, the temperature in oC is stored in registers starting at 0 times A0 and will keep the data for 24 hours. All temperature reading in location 0 times A0 through 0 times B7 will be cleared when INTO pin transitions from High to low. This is for PIC18F1220

Explanation / Answer

sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;

unsigned long ADRead;
unsigned int vDisp[3];
unsigned char Display[7];

void main() {

PORTA = 0;
TRISA = 0X01;
PORTB = 0;
TRISB = 0;
LCD_Init();
LCD_Cmd(_LCD_CURSOR_OFF);
LCD_Cmd(_LCD_CLEAR);
LCD_Out(1, 1, "Temp:");
//Display = "+125 'C";
Display[4] = 39; //'
Display[5]= 'C';
ADCON1 = 0x0E;
ADC_Init();
while (1){
ADRead = (ADC_Get_Sample(0) * 500) >> 10;
vDisp[0] = ADRead / 100;
vDisp[1] = (ADRead / 10) % 10;
vDisp[2] = ADRead % 10;
Display[1] = vDisp[0] + 48;
Display[2] = vDisp[1] + 48;
Display[3] = vDisp[2] + 48;
LCD_Chr(1, 8, Display[0]);
LCD_Chr(1, 9, Display[1]);
LCD_Chr(1, 10, Display[2]);
LCD_Chr(1, 11, Display[3]);
LCD_Chr(1, 12, Display[4]);
LCD_Chr(1, 13, Display[5]);
//LCD_Out(1, 8, );
delay_ms(200);
}
}


temperature >25celsius = only led1 blink
temperature <20celsius = only led2 blink
else, neither blink.

#include
#include
__CONFIG(0x3F32);

#define ADC_value
#define ADC_init
#define LED1 RB2
#define LED2 RB3

ADC_init ();

void main ()
{
TRISA = 0b00000001;
TRISB = 0b00000000;
PORTB = 0;
while (1);
{
unsigned int ADC_value = 0;
unsigned int temp = 0;

ADON = 1;
ADC_value = read_adc (0);
temp = (ADC_value/2);

if (temp < 20);
LED1 = 1;
LED2 = 0;
else if (temp > 25);
LED2 = 1;
LED1 = 0;
else
LED1 = 0;
LED2 = 0;
__delay_ms (100);
}
}

void ADC_init (void)
{

ADCON0 =0b10000001;
ADCON1 =0b10001110;
}

unsigned int read_adc (void)
{
unsigned int digit = 0;
__delay_ms (1);

GODONE = 1;
while (GODONE==1);
digit = (unsigned int)ADRESH<<8;
digit = digit + ADRESL;
return digit;
}

sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;

sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;

int t;
char a;
char lcd[] = "000 Degree";

void main()
{
ADCON1 = 0x04;
Lcd_Init();
Lcd_Cmd(_LCD_CURSOR_OFF);

do
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_out(1,1, "Temperature:");
t = ADC_Read(0);

t = t * 0.4887;
a = t%10;
lcd[2] = a + '0';

t = t/10;
a = t%10;
lcd[1] = a + '0';

t = t/10;
a = t%10;
lcd[0] = a + '0';

Lcd_out(2,1,lcd);
Delay_ms(100);
}while(1);
}

C Code


#include <16f877a.h>
#device adc=10
#fuses XT,NOLVP,NOWDT,NOPROTECT
#use delay(clock=4000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,ERRORS)
#include "lcd_flex.c"

#define LOAD PIN_B7
#define THRES 30.0   

int16 digital_reading;
float temp;

void main()
{
  
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(RA0_ANALOG);   
set_adc_channel(0);
delay_ms(1);   
  

lcd_init();   
output_low(LOAD);   
lcd_gotoxy(1,1);
lcd_putc("Temperature is:");   
  
while(1) // infinite loop
{
digital_reading = read_adc();
delay_us(100);   
temp = digital_reading * 0.4883;
lcd_gotoxy(1,2);   
printf(lcd_putc,"%2.1f C",temp);

if(temp>=THRES) output_high(LOAD);   
else output_low(LOAD);

delay_ms(1000);   
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote