• 回复
  • 收藏
  • 点赞
  • 分享
  • 发新帖

用PIC设计的数字温度计---实用!!

含电路图和源程序

http://www.dianyuan.com/blog/blog_comment_list.php?blar_id=77970

我的电源网博客新开张,希望大家有空去逛逛!!

谢谢!500) {this.resized=true; this.width=500; this.alt='这是一张缩略图,点击可放大。\n按住CTRL,滚动鼠标滚轮可自由缩放';this.style.cursor='hand'}" onclick="if(!this.resized) {return true;} else {window.open('http://u.dianyuan.com/bbs/u/61/163911199240652.jpg?x-oss-process=image/watermark,g_center,image_YXJ0aWNsZS9wdWJsaWMvd2F0ZXJtYXJrLnBuZz94LW9zcy1wcm9jZXNzPWltYWdlL3Jlc2l6ZSxQXzQwCg,t_20');}" onmousewheel="return imgzoom(this);">
全部回复(3)
正序查看
倒序查看
LV.1
2
2008-01-02 16:49
电路图
500) {this.resized=true; this.width=500; this.alt='这是一张缩略图,点击可放大。\n按住CTRL,滚动鼠标滚轮可自由缩放';this.style.cursor='hand'}" onclick="if(!this.resized) {return true;} else {window.open('http://u.dianyuan.com/bbs/u/61/163911199263730.jpg');}" onmousewheel="return imgzoom(this);">
0
回复
LV.1
3
2008-01-03 17:31
@
电路图[图片]500){this.resized=true;this.width=500;this.alt='这是一张缩略图,点击可放大。\n按住CTRL,滚动鼠标滚轮可自由缩放';this.style.cursor='hand'}"onclick="if(!this.resized){returntrue;}else{window.open('http://u.dianyuan.com/bbs/u/61/163911199263730.jpg');}"onmousewheel="returnimgzoom(this);">
以下是程序,编程器用的是微都自动测试设备工作室的WD_PP20编程器(PIC,AVR两用+实验板).编译器是CCS.

///////////////////////////////////////////////////////////////////////
//Filename: tsensor.c                                                //
//Revision: A                                                        //
//Creator: LourenceGuo                                               //
//Created Date: 2007-12-31                                           //
//                                                                   //
//Function:                                                          //
//This is a program to display the temperature w/ 5s bklight function//
//When open the machine, display:    Welcome !                       //
//                                Microchip MCU                   //
//Then display: Temperature:                                         //
//              XXXX Cdegree                                         //
//                                                                   //
//I/O and peripheral equipment:                                      //
//Temperature sensor: LM61, T=(V-500mV)/10                           //
//ADC PIN: AN1                                                       //
//AN0,AN1 ANALOG; A3 REF                                             //
//backlight control: B0                                              //
//LCD: 16PIN 1602LCD w/ backlight                                    //
///////////////////////////////////////////////////////////////////////


#include <16F873A.h>
#device ADC=10
#fuses HS,NOWDT,PROTECT,NOLVP
#use delay(clock=20000000)

#include "lcd.c"

float ad_value;
signed int ad_result;

int16 bk_light_counter=0;
int1 bk_light_flag=1;



#define PSW_KEY input(PIN_C0)
#define UP_KEY input(PIN_C1)
#define DOWN_KEY input(PIN_C2)

#define BK_LIGHT PIN_B0


void init();
void temp_ad();
void display();
void key_detection();


//============================================================================================================
#INT_TIMER1
void clock1_isr()
{
   set_timer1(0x3CAF);         // Interrupt every (0xFFFF-0x3CAF) * 0.2us = 50000 * 0.2us = 10ms

   // back light couter
   // ----------------------------------------------------------------------------
   if((bk_light_flag == 1) && (bk_light_counter < 500)) bk_light_counter ++;  // about 5 second
   else if(bk_light_counter==500)
      {
         output_low(BK_LIGHT);        // turn off back light
         bk_light_flag = 0;         // reset back light flag
      }
}
//============================================================================================================


//Detect any key press down
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
void key_detection()
{
   if((PSW_KEY==0)||(UP_KEY==0)||(DOWN_KEY==0))
   {
      output_high(BK_LIGHT);
      bk_light_flag=1;
      bk_light_counter=0;
   }
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////



//Initialize the LCD panel
//*************************************************************************************************************
void init()
{
   setup_adc_ports(RA0_RA1_ANALOG_RA3_REF);         // A0 A1 Ref=A3 for 16F873A, now Vref = 3.3V
   setup_adc(ADC_CLOCK_INTERNAL);

   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);      // setup interrupt timer1

   enable_interrupts(INT_TIMER1);      // Turn on interrupt timer1
   enable_interrupts(GLOBAL);          // Enabled all interruptions.

   output_high(BK_LIGHT);
   lcd_init();                         // Initialize lcd
   delay_ms(10);
   lcd_gotoxy( 1, 1);                  // go to the start position of the first line
   lcd_putc ("    Welcome !   ");      // display string in the first line
   delay_ms(1);
   lcd_gotoxy( 1, 2);                  // go to the start position of the second line
   lcd_putc (" Microchip MCU  ");      // display string in the second line

   delay_ms(2000);

}
//**************************************************************************************************************


// read temperature A/D data, AN1
// temperature calculator expression is: (ad_vaule(mv) - 500) / 10
void temp_ad()
{
      int8 tt;
      int16 ad_data ;
      {
         ad_data = 0;
         for(tt=0;tt<5;tt++)
         {
            set_adc_channel(1);                 //AN1
            delay_us(10);                       //Delay is need to wait A/D conversion over
            ad_data = ad_data + read_adc();     //add 5 times
         }

         ad_value = ad_data * 0.66;              // 3.3 / 5times
         ad_value = ad_value / 1.024;
         ad_value = (ad_value - 500) / 10;
         ad_result = ad_value;
       }

}

//display temprature value on the LCD
//////////////////////////////////////////////////////////////////////////////////////
void display()
{
  delay_ms(10);
  lcd_gotoxy( 1, 1);                      // go to the start position of the first line
  lcd_putc ("\fTemperature:    \n");      // \f--clear display,\n--go to start position of second line
  delay_ms(1);
  lcd_putc ("     Cdgree     ");
  delay_ms(1);

  lcd_gotoxy( 1, 2);                     // go to the start position of the second line
  lcd_putf (ad_result,4);                // display the temperature value, 4 digital

  //lcd_gotoxy( 1, 2);
  //lcd_putf (0xb7,1);

  delay_ms(1000);
}

//////////////////////////////////////////////////////////////////////////////////////


void main() {

  init();
  do
    {
      key_detection();
      temp_ad();
      display();
    }while(true);
}
0
回复
LV.1
4
2008-02-16 09:56
@
以下是程序,编程器用的是微都自动测试设备工作室的WD_PP20编程器(PIC,AVR两用+实验板).编译器是CCS./////////////////////////////////////////////////////////////////////////Filename:tsensor.c                                                ////Revision:A                                                        ////Creator:LourenceGuo                                              ////CreatedDate:2007-12-31                                          ////                                                                  ////Function:                                                          ////Thisisaprogramtodisplaythetemperaturew/5sbklightfunction////Whenopenthemachine,display:    Welcome!                      ////                                MicrochipMCU                  ////Thendisplay:Temperature:                                        ////              XXXXCdegree                                        ////                                                                  ////I/Oandperipheralequipment:                                      ////Temperaturesensor:LM61,T=(V-500mV)/10                          ////ADCPIN:AN1                                                      ////AN0,AN1ANALOG;A3REF                                            ////backlightcontrol:B0                                              ////LCD:16PIN1602LCDw/backlight                                    /////////////////////////////////////////////////////////////////////////#include#deviceADC=10#fusesHS,NOWDT,PROTECT,NOLVP#usedelay(clock=20000000)#include"lcd.c"floatad_value;signedintad_result;int16bk_light_counter=0;int1bk_light_flag=1;#definePSW_KEYinput(PIN_C0)#defineUP_KEYinput(PIN_C1)#defineDOWN_KEYinput(PIN_C2)#defineBK_LIGHTPIN_B0voidinit();voidtemp_ad();voiddisplay();voidkey_detection();//============================================================================================================#INT_TIMER1voidclock1_isr(){  set_timer1(0x3CAF);        //Interruptevery(0xFFFF-0x3CAF)*0.2us=50000*0.2us=10ms  //backlightcouter  //----------------------------------------------------------------------------  if((bk_light_flag==1)&&(bk_light_counter<500))bk_light_counter++;  //about5second  elseif(bk_light_counter==500)      {        output_low(BK_LIGHT);        //turnoffbacklight        bk_light_flag=0;        //resetbacklightflag      }}//============================================================================================================//Detectanykeypressdown///////////////////////////////////////////////////////////////////////////////////////////////////////////////voidkey_detection(){  if((PSW_KEY==0)||(UP_KEY==0)||(DOWN_KEY==0))  {      output_high(BK_LIGHT);      bk_light_flag=1;      bk_light_counter=0;  }}/////////////////////////////////////////////////////////////////////////////////////////////////////////////////InitializetheLCDpanel//*************************************************************************************************************voidinit(){  setup_adc_ports(RA0_RA1_ANALOG_RA3_REF);        //A0A1Ref=A3for16F873A,nowVref=3.3V  setup_adc(ADC_CLOCK_INTERNAL);  setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);      //setupinterrupttimer1  enable_interrupts(INT_TIMER1);      //Turnoninterrupttimer1  enable_interrupts(GLOBAL);          //Enabledallinterruptions.  output_high(BK_LIGHT);  lcd_init();                        //Initializelcd  delay_ms(10);  lcd_gotoxy(1,1);                  //gotothestartpositionofthefirstline  lcd_putc("    Welcome!  ");      //displaystringinthefirstline  delay_ms(1);  lcd_gotoxy(1,2);                  //gotothestartpositionofthesecondline  lcd_putc("MicrochipMCU  ");      //displaystringinthesecondline  delay_ms(2000);}//**************************************************************************************************************//readtemperatureA/Ddata,AN1//temperaturecalculatorexpressionis:(ad_vaule(mv)-500)/10voidtemp_ad(){      int8tt;      int16ad_data;      {        ad_data=0;        for(tt=0;tt
我的博客更新更多新程序和资料,新增变压器设计专题,欢迎大家来看一看.
0
回复