Академический Документы
Профессиональный Документы
Культура Документы
/* *****************************************************************************
; *
; Filename: *
; Date: *
; File Version: 001 *
; *
; Author: Jason Lopez *
; Company: AtomSoft *
; *
;***************************************************************************** */
#include <p18F4620.h>
#include <delays.h>
#include <string.h>
#include "lcd.h"
#pragma config WDT = OFF, LVP = OFF, OSC = HS, XINST = OFF
/************************************
Prototypes
*************************************/
void main(void);
unsigned char DECtoBCD(unsigned char DEC);
unsigned char DECtoASCII(unsigned char DEC,char part);
/************************************
Variables and Defines
*************************************/
#define ADCPin TRISAbits.TRISA0 // RA0/AN0 TRIS (DATA DIRECTION REGISTER)
LCD_Init();
DelayMS(100);
LCD_LINE(1);
LCD_STR((unsigned rom char*)" AtomSoftTech ");
LCD_LINE(2);
LCD_STR((unsigned rom char*)"Temp: ");
while(1){
ADCON0bits.GO = 1; //Start the conversion
while(ADCON0bits.DONE); //Wait until its done
result = ADRESH; //Load ADRESH into result
result <<= 8; //Shift over Result 8 bits to the left
result |= ADRESL; //OR in our LOW byte to finish off out INT
DegC = (result*5)/10;
DegC--;
DegF = DegC * 9;
DegF/=5;
1
D:\Users\Jason\Pictures\blog\lm35\LM35_ADC\18f2525.c
DegF+=32;
lcdtmp[0] = DECtoASCII(DegC,'h');
lcdtmp[1] = DECtoASCII(DegC,'l');
lcdtmp[2] = 'C';
lcdtmp[3] = '-';
lcdtmp[4] = DECtoASCII(DegF,'h');
lcdtmp[5] = DECtoASCII(DegF,'l');
lcdtmp[6] = 'F';
lcdtmp[7] = lcdtmp[8] = lcdtmp[9] = ' ';
LCD_LINE(2);
LCD_STR((unsigned rom char*)"Temp: ");
LCD_STR2(lcdtmp);
DelayMS(1000);
}
}
if(part == 'l')
myData = temp & 0x0F;
if(part == 'h')
myData = (temp >> 4) & 0x0F;
myData += 0x30;
return myData;
}
unsigned char DECtoBCD(unsigned char DEC){
unsigned char temph;
unsigned char templ;
unsigned char myData;
templ = DEC % 10;
temph = DEC / 10;
myData = (temph << 4) | templ;
2
D:\Users\Jason\Pictures\blog\lm35\LM35_ADC\lcd.c
/* *****************************************************************************
; *
; Filename: *
; Date: *
; File Version: 001 *
; *
; Author: Jason Lopez *
; Company: AtomSoft *
; *
;***************************************************************************** */
#include <p18F4620.h>
#include <delays.h>
#include <string.h>
#include "lcd.h"
#pragma config WDT = OFF, LVP = OFF, OSC = HS, XINST = OFF
/************************************
Prototypes
*************************************/
void main(void);
unsigned char DECtoBCD(unsigned char DEC);
unsigned char DECtoASCII(unsigned char DEC,char part);
/************************************
Variables and Defines
*************************************/
#define ADCPin TRISAbits.TRISA0 // RA0/AN0 TRIS (DATA DIRECTION REGISTER)
/************************************
Main
*************************************/
void main(void){
unsigned char tmp;
LCD_Init();
DelayMS(100);
LCD_LINE(1);
LCD_STR((unsigned rom char*)" AtomSoftTech ");
LCD_LINE(2);
LCD_STR((unsigned rom char*)"Temp: ");
while(1){
for(tmp=0;tmp<10;tmp++){
ADCON0bits.GO = 1; //Start the conversion
while(ADCON0bits.DONE); //Wait until its done
result = ADRESH; //Load ADRESH into result
result <<= 8; //Shift over Result 8 bits to the left
result |= ADRESL; //OR in our LOW byte to finish off out INT
1
D:\Users\Jason\Pictures\blog\lm35\LM35_ADC\lcd.c
avg[tmp] = result;
DelayMS(10);
}
result = 0;
for(tmp=0;tmp<10;tmp++){
result += avg[tmp];
}
result /= 10;
DegC = (result*5)/10;
DegC--;
DegF = DegC * 9;
DegF/=5;
DegF+=32;
lcdtmp[0] = DECtoASCII(DegF,'h');
lcdtmp[1] = DECtoASCII(DegF,'l');
lcdtmp[2] = 0xDF;
lcdtmp[3] = 'F';
lcdtmp[4] = ' ';
lcdtmp[5] = DECtoASCII(DegC,'h');
lcdtmp[6] = DECtoASCII(DegC,'l');
lcdtmp[7] = 0xDF;
lcdtmp[8] = 'C';
lcdtmp[9] = ' ';
LCD_LINE(2);
LCD_STR((unsigned rom char*)"Temp: ");
LCD_STR2(lcdtmp);
DelayMS(1000);
DelayMS(1000);
}
}
if(part == 'l')
myData = temp & 0x0F;
if(part == 'h')
myData = (temp >> 4) & 0x0F;
myData += 0x30;
return myData;
}
unsigned char DECtoBCD(unsigned char DEC){
unsigned char temph;
unsigned char templ;
unsigned char myData;
templ = DEC % 10;
temph = DEC / 10;
myData = (temph << 4) | templ;
2
D:\Users\Jason\Pictures\blog\lm35\LM35_ADC\lcd.h
#ifndef __LCD_H
#define __LCD_H
#include <delays.h>
#include <p18cxxx.h>
#define CMD 0
#define TXT 1
#define LOWER 0
#define UPPER 1
#define DISPLAY 1
#define CURSOR 0
#define RIGHT 1
#define LEFT 0
void WaitLCDBusy(void);
void LCD_Init(void);
void LCD_DATA(unsigned char data,unsigned char type);
void LCD_NYB(unsigned char nyb);
void LCD_STR(unsigned rom char *text);
void LCD_LINE(char line);
void ShiftDisplay(unsigned char DC,unsigned char RL);
void DelayMS(unsigned int ms);
void LCD_CLEAR(unsigned char line);
void LCD_POS(unsigned char line);
void LCD_STR2(unsigned char *text);
extern unsigned char BF;
#endif