PC與單片機雙向通訊智能溫控程序
#include <AT89X51.H>
#include <intrins.h>
#define Key_UP P1_0
#define Key_DOWN P1_1
#define Key_SET P1_2
#define RelayOutPort P2_0
#define LEDPort P0
#define DELPort P2_1
#define LEDTwoC P3_6
#define LEDThreeC P3_7
#define TMPort P2_7
#define INBUF_LEN 5 //數據長度
unsigned char inbuf1[INBUF_LEN]={ 0 , 0 , 0 , 0 , 0 } //發送緩沖區
unsigned char inbuf2[50] //接收緩沖區
unsigned char count3
void init_serialcomm( void )
{
SCON = 0x50 //SCON: serail mode 1, 8-bit UART, enable ucvr
TMOD |= 0x20 //TMOD: timer 1, mode 2, 8-bit reload
PCON |= 0x80 //SMOD=1
TH1 = 0xFA //Baud:4800 fosc=11.0592MHz
IE |= 0x90 //Enable Serial Interrupt
TR1 = 1 // timer 1 run
}
//向串口發送一個字符
void send_char_com( unsigned char ch)
{
SBUF=ch
while (TI== 0 )
TI= 0
標簽:
include
intrins
define
Key_UP
上傳時間:
2014-11-29
上傳用戶:風之驕子
TLC2543是TI公司的12位串行模數轉換器,使用開關電容逐次逼近技術完成A/D轉換過程。由于是串行輸入結構,能夠節省51系列單片機I/O資源;且價格適中,分辨率較高,因此在儀器儀表中有較為廣泛的應用。
TLC2543的特點
(1)12位分辯率A/D轉換器;
(2)在工作溫度范圍內10μs轉換時間;
(3)11個模擬輸入通道;
(4)3路內置自測試方式;
(5)采樣率為66kbps;
(6)線性誤差±1LSBmax;
(7)有轉換結束輸出EOC;
(8)具有單、雙極性輸出;
(9)可編程的MSB或LSB前導;
(10)可編程輸出數據長度。
TLC2543的引腳排列及說明
TLC2543有兩種封裝形式:DB、DW或N封裝以及FN封裝,這兩種封裝的引腳排列如圖1,引腳說明見表1
TLC2543電路圖和程序欣賞
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit clock=P1^0; sbit d_in=P1^1;
sbit d_out=P1^2;
sbit _cs=P1^3;
uchar a1,b1,c1,d1;
float sum,sum1;
double sum_final1;
double sum_final;
uchar duan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar wei[]={0xf7,0xfb,0xfd,0xfe};
void delay(unsigned char b) //50us
{
unsigned char a;
for(;b>0;b--)
for(a=22;a>0;a--);
}
void display(uchar a,uchar b,uchar c,uchar d)
{
P0=duan[a]|0x80;
P2=wei[0];
delay(5);
P2=0xff;
P0=duan[b];
P2=wei[1];
delay(5);
P2=0xff;
P0=duan[c];
P2=wei[2];
delay(5);
P2=0xff;
P0=duan[d];
P2=wei[3];
delay(5);
P2=0xff;
}
uint read(uchar port)
{
uchar i,al=0,ah=0;
unsigned long ad;
clock=0;
_cs=0;
port<<=4;
for(i=0;i<4;i++)
{
d_in=port&0x80;
clock=1;
clock=0;
port<<=1;
}
d_in=0;
for(i=0;i<8;i++)
{
clock=1;
clock=0;
}
_cs=1;
delay(5);
_cs=0;
for(i=0;i<4;i++)
{
clock=1;
ah<<=1;
if(d_out)ah|=0x01;
clock=0;
}
for(i=0;i<8;i++)
{
clock=1;
al<<=1;
if(d_out) al|=0x01;
clock=0;
}
_cs=1;
ad=(uint)ah;
ad<<=8;
ad|=al;
return(ad);
}
void main()
{
uchar j;
sum=0;sum1=0;
sum_final=0;
sum_final1=0;
while(1)
{
for(j=0;j<128;j++)
{
sum1+=read(1);
display(a1,b1,c1,d1);
}
sum=sum1/128;
sum1=0;
sum_final1=(sum/4095)*5;
sum_final=sum_final1*1000;
a1=(int)sum_final/1000;
b1=(int)sum_final%1000/100;
c1=(int)sum_final%1000%100/10;
d1=(int)sum_final%10;
display(a1,b1,c1,d1);
}
}
標簽:
2543
TLC
上傳時間:
2013-11-19
上傳用戶:shen1230
SHUZIZHONG顯示電路
源程序如下:
#include <reg51.h>#include <intrins.h>
unsigned char data dis_digit;
unsigned char code dis_code[]={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};unsigned char data dis_buf[16];unsigned char data dis_index;char hour,min,sec,wang,year,mouth,day;unsigned char sec100;
標簽:
數字
顯示電路
上傳時間:
2013-11-24
上傳用戶:fdmpy