跪求各位大大~現在我這邊有兩個程式 首先我將8051+ADC0804 此程式能動作,實做出來也能動~再來8051+RS232(但是這輸出只用4位元如果可以的話能幫忙讓它輸出8位元)此程式能動作,實做出來也能動,問題來了我將這兩個程式合在一起卻沒功能了,可否有大師幫幫忙,小弟已經兩個多禮拜了~都在耗在此程式上了~望請各位大大幫幫忙。附上程式
8051-ADC0804
#include<reg51.h>
sbit wr= P2^0; // Write pin. It is used to start the conversion.
sbit rd= P2^1; // Read pin. It is used to extract the data from internal register to the output pins of ADC.
sbit intr= P2^2; // Interrupt pin. This is used to indicate the end of conversion. It goes low when conversion is complete.
void transmit() // Function for serial tranmission of data.
{
SBUF=P1;
while(TI==0);
TI=0;
}
void delay(unsigned int msec ) // The delay function provides delay in msec.
{
int i ,j ;
for(i=0;i<msec;i++)
for(j=0; j<1275; j++);
}
void adc() //Function to read the values from ADC and tranmit serially.
{
rd=1;
wr=0;
delay(2);
wr=1;
while(intr==1);
rd=0;
transmit();
delay(2);
intr=1;
}
void init() // Intialize timer 1 in mode 2 for serial transmission. The baud rate is set to 9600bps.
{
TMOD=0x20;
TH1=0xFD;
SCON=0x50;
TR1=1;
}
附上電路圖,謝謝各位的幫忙
他的程式碼
// Program to read the values of ADC and serially tranmitting it to PC.
#include<reg51.h>
sbit wr= P2^0; // Write pin. It is used to start the conversion.
sbit rd= P2^1; // Read pin. It is used to extract the data from internal register to the output pins of ADC.
sbit intr= P2^2; // Interrupt pin. This is used to indicate the end of conversion. It goes low when conversion is complete.
void transmit() // Function for serial tranmission of data.
{
SBUF=P1;
while(TI==0);
TI=0;
}
void delay(unsigned int msec ) // The delay function provides delay in msec.
{
int i ,j ;
for(i=0;i<msec;i++)
for(j=0; j<1275; j++);
}
void adc() //Function to read the values from ADC and tranmit serially.
{
rd=1;
wr=0;
delay(2);
wr=1;
while(intr==1);
rd=0;
transmit();
delay(2);
intr=1;
}
void init() // Intialize timer 1 in mode 2 for serial transmission. The baud rate is set to 9600bps.
{
TMOD=0x20;
TH1=0xFD;
SCON=0x50;
TR1=1;
}