#include注意:溫度可能不是很准確,因為我的電壓---溫度對應關系沒有進行仔細的測量。。粗略為y=-x+151#define uchar unsigned char #define uint unsigned int #define PCF8591 0x90 sbit SCL=P2^0; sbit SDA=P2^1; sbit spk=P1^4; sbit WEI=P2^7; //wei sbit DUAN=P2^6; //duan unsigned char code dofly_DuanMa[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x40};// 顯示段碼值0~9 unsigned char code dofly_WeiMa[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//分別對應相應的數碼管點亮,即位碼 void delay(int z) { while(z--); } void Screen(int i,int n) { P0=0; DUAN=1; DUAN=0; P0=dofly_WeiMa[i]; WEI=1; WEI=0; P0=dofly_DuanMa[n]; DUAN=1; DUAN=0; delay(250); } void Get_out_print(uchar temperatureNum) { if(temperatureNum/100>0) { Screen(3,temperatureNum/100); temperatureNum%=100; } if(temperatureNum/10>0) { Screen(4,temperatureNum/10); } Screen(5,temperatureNum%10); Screen(7,12); //顯示c } void delay() //延時4-5個微秒 {;;} void delay_1ms(uint z) { uint x,y; for(x=z;x>0;x--) for(y=110;y>0;y--) ; } void start() { SDA=1; delay(); SCL=1; delay(); SDA=0; delay(); } void stop() { SDA=0; delay(); SCL=1; delay(); SDA=1; delay(); } void respons() { uchar i; SCL=1; delay(); while((SDA==1)&&(i<250)) i++; SCL=0; delay(); } void init() { SDA=1; delay(); SCL=1; delay(); } uchar read_byte() { uchar i,k; SCL=0; delay(); SDA=1; delay(); for(i=0;i<8;i++) { SCL=1; delay(); k=(k<<1)|SDA; SCL=0; delay(); } return k; } void write_byte(uchar date) { uchar i,temp; temp=date; for(i=0;i<8;i++) { temp=temp<<1; SCL=0; delay(); SDA=CY; delay(); SCL=1; delay(); } SCL=0; delay(); SDA=1; delay(); } void write_add(uchar control,uchar date) { start(); write_byte(PCF8591); respons(); write_byte(control); respons(); write_byte(date); respons(); stop(); } uchar read_add(uchar control) { uchar date; start(); write_byte(PCF8591); respons(); write_byte(control); respons(); start(); write_byte(PCF8591+1); respons(); date=read_byte(); stop(); return date; } uchar temperatureNum=0; void main() { TMOD= 0x01; EA=1; ET0=1; TR0=1; init(); while(1) { temperatureNum=read_add(0x41); //確定路 Get_out_print(151-temperatureNum); } } void Timer0_isr(void) interrupt 1 { TH0=0xfe; TL0=0; if(temperatureNum<118) spk=!spk; }