|
//ICC-AVR application builder : 28-Nov-2007 By HP Zhou
// Target : M8
// Crystal: 8.0000Mhz
#include <iom8v.h>
#include <macros.h>
#define uint unsigned int
unsigned char Sc;
unsigned char Tdata;
unsigned char Addr ;
//PORT Initialize >>>>>>>>
void port_init(void)
{
PORTC = 0xF0;
DDRC = 0x00;
PORTD = (1<<PD2);
DDRD = (1<<DDD2);
}
//UART0 initialize >>>>>>>
// desired baud rate: 9600
// actual: baud rate:9615 (0.2%)
// char size: 8 bit,1 bit stop
// parity: Disabled
void uart0_init(void)
{
UCSRB = 0x00; //disable while setting baud rate
UCSRA = 0x00;
UCSRC = BIT(URSEL) | 0x06;
//UCSRC = (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0);
UBRRL = 0x33; //set baud rate lo
UBRRH = 0x00; //set baud rate hi
UCSRB = 0xF8;
// ;UCR=0XD8;
//UCSRB = (1<<RXEN)|(1<<TXEN);
}
// Delay_Ms >>>>>>>>>
void delayMs(uint i)
{uint j;
for(;i!=0;i--)
{for(j=8000;j!=0;j--) ;}
}
// UART TRANSMIT >>>>>>>>>
void Transmit(Tdata)
{
PORTD&=0XFD;
while (!(UCSRA&(1<<UDRE))) //wait txr be zeno
UDR = Tdata;
while (UCSRA&(1<<TXC))
{
delayMs (5);
PORTD = (1<<PD2);
}
}
// UART RECIVE DATA >>>>>>>>>
unsigned char Rdata(void)
{
//;while (!(USR&0X80))
while (!(UCSRA&(1<<RXC))) //wait txr be zeno
return UDR;
}
//Rdata = UDR;
// Read PORTC STAUTE >>>>>>>>>
unsigned char Staute(Sc)
{
unsigned char Sc1;
Sc = 0xF3;
Sc1 = 0xF3;
for(;;)
{
Sc1 = PINC;
if (Sc^Sc1)
{
delayMs(20);
Sc = PINC;
if (Sc & Sc1)
Sc = Sc1;
return Sc;
}
}
}
// Main program >>>>>>>>>
void main (void)
{
Addr = C1; // ??地址变量
unsigned char tchr;
unsigned char stau;
port_init();
uart0_init();
//GIMSK = 0X00;
CLI();
for(;;)
{
tchr = Rdate();
stau = Staute();
while (tchr & Addr)
Transmit(stau);
delayMs(10);
}
}
个位高手,帮我看看,还有那些问题,. 地址从何出输入?. |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|