📄 main.c
字号:
//ICC-AVR application builder : 2008-5-9 21:38:30
// Target : M16
// Crystal: 16.000Mhz
#include"include.h"
#include "main.h"
//端口初始化
//数据寄存器 PORTx 读写寄存器
//引脚配置为输入PORTx=1 上拉电阻使能 \\PORTx=0 关闭上拉电阻 \\复位时引脚为高阻态
//引脚配置为输出PORTx=1 引脚输出高电平"1" \\PORTx=0 引脚输出低电平"0"
//数据方向寄存器 DDRx 读写寄存器 =1引脚配置为输出 =0引脚配置为输入
//端口输入引脚 PINx 只读寄存器
void port_init(void)
{
/*PA上拉电阻使能 引脚配置为输入*/
PORTA = 0xFF;
DDRA = 0x00;
/**/
PORTB = 0x20;
DDRB |= (1<<5)|(1<<7);
/*PC上拉电阻使能 引脚配置为输入*/
PORTC = 0xFF; //m103 output only
DDRC = 0x00;
/**/
PORTD = 0x00;
DDRD = 0x20;
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
Uart0_Init();
Timer0_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x01; //timer interrupt sources
Power_LED_Drown();
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void DelaymS(unsigned int cnt)
{
unsigned int i;
do{
i = 5000;
do{
asm("nop");
asm("nop");
} while(--i);
}while (--cnt);
}
void main(void)
{
unsigned int i;
struct StructOfProtocol *p_buf;
struct Device51_StructOfProtocol *C51_buf;
struct data *communication;
p_buf = (struct StructOfProtocol *)Buffer485;
C51_buf = (struct Device51_StructOfProtocol *)C51Buffer485;
init_devices();
Device_Address = 0x01;
C51_buf->Address = 0x01;
C51_buf->Command = 0x02;
C51_buf->Data[0] = 0x03;
C51_buf->Data[1] = 0x04;
C51_buf->Data[2] = 0x05;
C51_buf->Data[3] = 0x06;
C51_buf->Length = 0x05;
Power_LED_Light();
// BUS_SendPacket_51Device();
while(1)
{
if(communication->pc_rxd)
{
communication->pc_rxd = 0;
max485_on();
UDR = 0x31;
}
}
}
/*
{
Cyc_manage = 0x02;
for(i=1;i<9;i*=2)
{
switch(Cyc_manage&i)
{
case 1://处理跟PC通讯部分
communication_with_pc();
break;
case 2://处理跟51控制板通讯部分
communication_with_51director();
break;
case 4://取数据发送给51板
update_data_51director();
break;
case 8://检查按键发送给51控制板
communication_ReadSwitch();
break;
default:
break;
}
}
} */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -