Temperature detection and heating through the 502AT thermistor on the MC9S128

Publisher:清新心情Latest update time:2021-08-16 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#include       /* common defines and macros */

#include "derivative.h"      /* derivative-specific definitions */

#define SDA PTT_PTT1 //Data port 1

#define SCL PTT_PTT0 // Clock

#define DC  PTT_PTT3  

#define RST PTT_PTT2

/******************************/

/*void delay(uint a){

  uint b;

  for(a;a>0;a--)

    for(b=1000;b>0;b--);

} */

void InitAD(void) {     

  ATD0DIEN=0X00;

  ATD0CTL1=0X20;

  ATD0CTL2=0X40;

  ATD0CTL3=0X8C;

  ATD0CTL4=0X03;

  ATD0CTL5=0X20;

  

}

/********************************/

const uint m[]={ 8829,8494,8166,7852,7552,7266,6992,6731,6481,6242,

                    6013,5782,5581,5379,5185,5000,4821,4650,4487,4329,

                    4170,4033,3894,3760,3631,3508,3390,3276,3167,3062,

                    2962,2864,2770,2680,2593,2510,2429,2352,2278,2206,

                    2138,2070,2006,1944,1884,1826,1771,1717,1665,1616, 

                    1568,1521,1476,1433,1391,1351,1312,1274,1238,1200, 

                    1169,1136,1104,1073,1043,1014,986,959,933,908};  

const byte tab_num[][16]= //Digital font

 

{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00},/*"0",0*/

 

{0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},/*"1",1*/

 

{0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00},/*"2",2*/

 

{0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00},/*"3",3*/

 

{0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00},/*"4",4*/

 

{0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00},/*"5",5*/

 

{0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00},/*"6",6*/

 

{0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00},/*"7",7*/

 

{0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00},/*"8",8*/

 

{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00},/*"9",9*/

 

};

 

/*************************************/

void wrdata(byte data){

  byte i=8;

  DC=1;

  SCL=0;

  while(i--){

    if(data&0x80)

      SDA=1;

    else

      SDA=0;

    SCL=1;

    _asm(nop);

    SCL=0;

    data<<=1;

  }

  

}

void wrcmd(byte cmd){

  byte i=8;

  DC=0;

  SCL=0;

  while(i--){

    if(cmd&0x80)

      SDA=1;

    else

      SDA=0;

    SCL=1;

    _asm(nop);

    SCL=0;

    cmd<<=1;

  }

}

void set_xy(byte x,byte y){

  wrcmd((y|0xb0));

  wrcmd((x&0x0f));

  wrcmd(((x&0xf0)>>4)|0x10);

}

void clear_oled(void)  

{  

   byte page,x;

   set_xy(0,0);

    for(page=0;page<9;page++)

    {

        for(x=0;x<128;x++){wrdata(0x00);}

        set_xy(0,page);

    } 

}

 

void init_oled(void){

  DDRT=0XFF;

  SCL=1;

  RST=0;

  _asm(nop);

  _asm(nop);

  RST=1;

  wrcmd(0xae);

  wrcmd(0xD5);

  wrcmd(0x80);

  wrcmd(0xA8);

  wrcmd(0x3f);

  wrcmd(0xd3);

  wrcmd(0x00);

  wrcmd(0x40);

  wrcmd(0x8d);

  wrcmd(0x14);

  wrcmd(0x20);

  wrcmd(0x02);

  wrcmd(0xa1);

  wrcmd(0xc8);

  wrcmd(0xea);

  wrcmd(0x12);

  wrcmd(0x81);

  wrcmd(0xef);

  wrcmd(0xd9);

  wrcmd(0xf1);

  wrcmd(0xdb);

  wrcmd(0x30);

  wrcmd(0xa4);

  wrcmd(0xa6);

  wrcmd(0xaf);

  clear_oled();

}

void display_num(byte x,byte y,byte w) {

    byte c;

    set_xy(x,y);

    for(c=0;c<8;c++)   {  wrdata(tab_num[w][c]);  }

    set_xy(x,y+1);

    for(c=8;c<16;c++)  {  wrdata(tab_num[w][c]);  }

}

void main(void){

  unsigned char v;

  uint t,t1,t2,t3,t4,t5,x,t7,t8,t9,t10,t11;

  head t6;

  DDRT=0XFF;

  DDRB=0XFF;

  DDRP=0XFF;

  InitAD();

  init_oled();

  for(;;) {

     PTP_PTP3=0;

     while(!ATD0STAT2L_CCF0){

    ;}

     v=ATD0DR0L;

     t=(int)v;

     t6=t*100000/(1023-t);

     for(x=0;x<70;x++){

      if(t6>m[x+1]&&t6       t3=x;

       break;

     }

     }

     t1=t/100;

     t2=(t%100)/10;

     t11=t%10;

     t4=t6/1000;

     t5=(t6%1000)/100;

     t7=(t6%100)/10;

     t8=t6%10;

     t9=(t3/10)+1;

     t10=t3%10;  

     display_num(16,0,t1);

     display_num(24,0,t2);

     display_num(32,0,t11);

     display_num(16,3,t4);

     display_num(24,3,t5);

     display_num(32,3,t7);

     display_num(40,3,t8);

     display_num(16,5,t9);

     display_num(24,5,t10);

     _FEED_COP();   

}

Reference address:Temperature detection and heating through the 502AT thermistor on the MC9S128

Previous article:Bootloader for S12(X) microcontrollers
Next article:Output the voltage value of different AD buttons through AD sampling

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号