ตัวอย่าง
uart.c
/*****************************************************************************************
* File Name : uart.c
*
* Created on: Sep 17, 2010
* Author: Kang Usman
* File Description:
******************************************************************************************/
#include <REGX52.H>
#include "uart.h"
#include <stdio.h>
idata char modem_buffer[RX_BUFFER_SIZE];
idata int modem_buffer_index, modem_buffer_size;
idata unsigned char modem_rx_complete;
idata char modem_buffer_overflow;
float temp, humi;
void uartisr(void) interrupt 4 using 1
{
unsigned char c;
if (RI)
{
c=SBUF;
RI=0;
if (c=='A')
printf("SHT11\n");
if (c=='B')
{
printf("%2.1fC;%2.1f%%\n",temp,humi);
}
}
}
void InitUART()
{
TL2 = 0xf7; //
TH2 = 0xff; // 9600 bps at 11.0592 MHz
RCAP2L = 0xDC;
RCAP2H = 0xff;
T2CON = 0x34; // timer2 as baud rate generator
SCON = 0x50; // enable serial com mode1 = 8 bit UART
ES = 1; // enable serial interrupt
TI=1;
EA=1;
}
void clearbuffer()
{
//com_out =0;
modem_buffer_index=0;
modem_buffer_size=0;
modem_rx_complete=0;
}
และ
uart.h
#ifndef UART_H_
#define UART_H_
// USART Receiver buffer
#define RX_BUFFER_SIZE 2
extern idata char modem_buffer[RX_BUFFER_SIZE];
extern idata int modem_buffer_index, modem_buffer_size;
extern idata unsigned char modem_rx_complete;
extern idata char modem_buffer_overflow;
extern float temp, humi;
void InitUART();
void clearbuffer();
#endif /* UART_H_ */
จากคุณ tateki tanaka (A:192.168.0.16 X:118.173.150.176)
Header File (นามสกุล .h) มันคืออะไร ไม่เข้าใจ ช่วยอธิบายทีครับ
uart.c
/*****************************************************************************************
* File Name : uart.c
*
* Created on: Sep 17, 2010
* Author: Kang Usman
* File Description:
******************************************************************************************/
#include <REGX52.H>
#include "uart.h"
#include <stdio.h>
idata char modem_buffer[RX_BUFFER_SIZE];
idata int modem_buffer_index, modem_buffer_size;
idata unsigned char modem_rx_complete;
idata char modem_buffer_overflow;
float temp, humi;
void uartisr(void) interrupt 4 using 1
{
unsigned char c;
if (RI)
{
c=SBUF;
RI=0;
if (c=='A')
printf("SHT11\n");
if (c=='B')
{
printf("%2.1fC;%2.1f%%\n",temp,humi);
}
}
}
void InitUART()
{
TL2 = 0xf7; //
TH2 = 0xff; // 9600 bps at 11.0592 MHz
RCAP2L = 0xDC;
RCAP2H = 0xff;
T2CON = 0x34; // timer2 as baud rate generator
SCON = 0x50; // enable serial com mode1 = 8 bit UART
ES = 1; // enable serial interrupt
TI=1;
EA=1;
}
void clearbuffer()
{
//com_out =0;
modem_buffer_index=0;
modem_buffer_size=0;
modem_rx_complete=0;
}
และ
uart.h
#ifndef UART_H_
#define UART_H_
// USART Receiver buffer
#define RX_BUFFER_SIZE 2
extern idata char modem_buffer[RX_BUFFER_SIZE];
extern idata int modem_buffer_index, modem_buffer_size;
extern idata unsigned char modem_rx_complete;
extern idata char modem_buffer_overflow;
extern float temp, humi;
void InitUART();
void clearbuffer();
#endif /* UART_H_ */
จากคุณ tateki tanaka (A:192.168.0.16 X:118.173.150.176)