📄 touchinterface.c
字号:
/*===========================
TouchInterface.c
===========================*/
#include "TouchInterface.h"
unsigned char test_str[]="123456789\n";
unsigned int buzzer_time=100;
/*===========================
===========================*/
void McuInit(void)
{
CLI();
//PORT
PORTA=0xff;
DDRA =0x90;
PORTB=0xff;
DDRB =0x10;
PORTC=0xff;
DDRC =0x00;
PORTD=0xff;
DDRD =0x00;
PORTE=0xff;
DDRE =0x00;
//
WDR();
WDTCR=0x18;
WDTCR=0x1f;
//UART0 initialisation
// desired baud rate: 9600
// actual: baud rate:9600 (0.0%)
// char size: 8 bit
// parity: Disabled
UCSR0B = 0x00; //disable while setting baud rate
UCSR0A = 0x00; //disable while setting baud rate
UBRR0L =0x47; //set baud rate
UBRR0H = 0x00;
UCSR0C = 0x86;
UCSR0A = 0x00; //enable
UCSR0B = 0x98; //enable
//UART1 initialisation
// desired baud rate:19200
// actual baud rate:19200 (0.0%)
// char size: 8 bit
// parity: Disabled
UCSR1B = 0x00; //disable while setting baud rate
UCSR1A = 0x00; //disable while setting baud rate
UBRR1L =0x23; //set baud rate
UBRR1H = 0x00;
UCSR1C = 0x86;
UCSR1A = 0x00; //enable
UCSR1B = 0x98; //enable
//TIMER0 initialisation - prescale:256
// WGM: Normal
// desired value: 1mSec
// actual value: 0.995mSec (0.5%)
TCCR0= 0x00; //stop
TCNT0= 0xD5; //set count
OCR0= 0x2B; //set compare value
TCCR0= 0x04; //start timer
//MCU
MCUCR= 0x00;
EMCUCR = 0x00;
// GIMSK= 0x00;
TIMSK= 0x02; //timer interrupt sources
ETIMSK=0x00;
GICR= 0x00;
PCMSK0=0x00;
PCMSK1=0x00;
SEI();
}
/*===========================
===========================*/
void main(void)
{
McuInit();
DelayMs(100);
EN485RXD();
//for test
UartTxdStr(RS232_PORT,test_str,10);
UartTxdStr(RS485_PORT,test_str,10);
LEDon();
while(1)
{
WDR();
}
}
/*===========================
===========================*/
#pragma vector=USART0_RXC_vect
__interrupt void uart0_rx_isr(void)
{
//uart has received a character in UDR
unsigned char tmp;
tmp=UDR0;
UartTxd0(tmp);
/* EN485TXD();
UartTxd1(tmp);
EN485RXD();*/
}
/*===========================
===========================*/
#pragma vector=USART1_RXC_vect
__interrupt void uart1_rx_isr(void)
{
//uart has received a character in UDR
unsigned char tmp;
tmp=UDR1;
// UartTxd0(tmp);
EN485TXD();
UartTxd1(tmp);
EN485RXD();
}
/*===========================
===========================*/
#pragma vector=TIMER0_OVF_vect
__interrupt void timer0_ovf_isr(void) //1mS
{
TCNT0= 0xD5; //reload counter value
LEDblink();
if(buzzer_time)
{
buzzer_time--;
BUZZERon();
}
else
{
BUZZERoff();
}
}
/*===========================
END
===========================*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -