?? 24cxxmain.c
字號(hào):
#include<iom16v.h>
#include<macros.h>
#include"xd.h"
#define XDmain
#include"xdprj.h"
uchar r_buf[64];
uchar w_buf[64];
void main()
{
uint i;
uchar *r;
uint b;
uint c;
uchar *w;
uint x;
uint y;
tms(100);
//-----初始化cpu------
setreg_m16(); //初始化cpu
for(i=0;i<64;i++) //清主機(jī)讀和寫緩存區(qū)
r_buf[i]=w_buf[i]=0;
for(i=0;i<64;i++) //寫緩存區(qū)賦初值
w_buf[i]=i;
r=r_buf; //讀參數(shù)
b=0x00;
c=64;
w=w_buf; //寫參數(shù)
x=0x00;
y=64;
wt24c(w,x,y); //寫
txd_buf[68]=syserr;
rd24c(r,b,c); //讀
//-----讀出的數(shù)據(jù)發(fā)送到PC-----
for(i=0;i<64;i++)
txd_buf[i]=r_buf[i];
txd_buf[69]=syserr;
txdpo(txd_buf, 70);
while(1);
//----------------------------
c=0;
}
//-------------------------------------------------------------------------------------------------------------------------
//ICC-AVR application builder : 2005-11-9 22:09:34
// Target : M16
// Crystal: 8.0000Mhz
void port_init(void)
{
PORTA = 0xff;
DDRA = 0x00;
PORTB = 0xff;
DDRB = 0x00;
PORTC = 0xff; //m103 output only
DDRC = 0b00000011; //設(shè)PC0和PC1為輸出
PORTD = 0xff;
DDRD = 0x00;
}
//TWI initialize
// bit rate:100
void twi_init(void)
{
TWCR= 0X00; //disable twi
TWBR= 0x64; //set bit rate
TWSR= 0x00; //set prescale
TWAR= 0x00; //set slave address
TWCR= 0x04; //enable twi
}
//UART0 initialize
// desired baud rate: 9600
// actual: baud rate:9615 (0.2%)
// char size: 8 bit
// parity: Disabled
void uart0_init(void)
{
UCSRB = 0x00; //disable while setting baud rate
UCSRA = 0x00;
UCSRC = BIT(URSEL) | 0x06;
UBRRL = 0x33; //set baud rate lo
UBRRH = 0x00; //set baud rate hi
UCSRB = 0x08;
}
//call this routine to initialize all peripherals
void setreg_m16(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
twi_init();
uart0_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -