📄 sys_init.c
字号:
/**************************************************************************************************
Copyright (C), 2007-2008, wanyi Tech. Co., Ltd.
FileName :drv_io.c
Author :kevin
modify :
Version :1.0
Date :2007-9-06
Description :half auto design for driver io function
Function List :void init_io(void)
***************************************************************************************************/
#include "system.h"
#define LEDCON (1<<25)
#define LEDCON1 (1<<20)
unsigned char flag1=0,flag2=0;
uint16 re_crc_value;//串口接收到的CRC校验码
extern uint8 course_delay;
extern uint16 show_delay;
extern uint16 XAIOGUANDU,FENCHEN,TOUGUOLI;
extern uint8 rcv_new;
extern uint8 rcv_buf[40];
extern uint8 real_second_value;
char ds[7][8];
char st[8][8];
status_parm STU[8];
amp_parm AMP_P[7];
/****************************************************************************
* 名称:I2C_Init()
* 功能:I2C初始化,包括初始化其中断为向量IRQ中断。
* 入口参数:无
* 出口参数:无
****************************************************************************/
void I2C_Init(void)
{
PINSEL0 = (PINSEL0&0xFFFFFF0F) | 0x50;
/* 设置I2C时钟为100KHz */
I2SCLH = I2SCLL = 14; // 晶振为11.0592MHz,Fpclk = 2.7648MHz
I2CONCLR = 0x2C;
I2CONSET = 0x40;
/* 设置I2C中断允许 */
VICIntSelect&=~(1<<9);// = 0x00000000; // 设置所有通道为IRQ中断
VICVectCntl15 = 0x29; // I2C通道分配到IRQ slot 10
VICVectAddr15 = (int)IRQ_I2C; // 设置I2C中断向量地址 10
VICIntEnable |=0x00000200;//(1<<9);//= 0x00000200; // 使能I2C中断
}
/**************************************************************************************************
Function: // void init(void)
Description: // for init system
Calls: //
Called By: // main ()
Table Accessed: // none
Table Updated: // none
Input: // void
Output: // none
Return: // void
Others: // none
***************************************************************************************************/
void init_sys(void)
{uint8 kk;
init_io();
I2C_Init();
UART0_Ini(115200);//init_ad();
init_timer0();
init_timer1();
UART1_Ini(9600);
DelayNS(200);
init_LCD();
// init_int0 ();
// init_int2 ();
// InitCAN(0);
// init_hc595();
// set_hc595_start;
// init_motor();
IRQEnable();
for(kk=0;kk<39;kk++)
rcv_buf[kk]=0;
real_second_value=0;
write_clock(SECOND_ADDRESS,real_second_value);
clr_LCD_screen();
//-----------------------------------------------
}
/**************************************************************************************************
Function: // void IRQ_Timer0 (void)
Description: // for timer0 interrupt
Calls: // none
Called By: // init ()
Table Accessed: // none
Table Updated: // none
Input: // void
Output: // none
Return: // void
Others: // none
***************************************************************************************************/
uint32 Time0_cnt;
void __irq IRQ_Timer0 (void)
{
uint8 i,j,k;
T0IR = 0x01; // 清除中断标志
if(show_delay!=0) {show_delay--;}
if(course_delay!=0) course_delay--;
//if(rcv_new!=0)
// {
if(rcv_new==1) // 24 byte
{//crc_temp=rec_crc16(ptr,); //取得CRC校验码
// re_crc_value=(rcv_buf[28]<<8)|rcv_buf[29];
rcv_new=0;k=0;
for(i=0;i<7;i++) //读取DSP放大板工作参数
{
for(j=0;j<4;j++)
{
AMP_P[i].byte[j]=rcv_buf[k+2]; //信息字和序列号不用,向后偏移两个字节.
k++;
}
}
for(i=0;i<7;i++)
{
sprintf(ds[i],"%f",AMP_P[i].fat);
}
}
else if(rcv_new==2) // 30 byte
{
// re_crc_value=(rcv_buf[32]<<8)|rcv_buf[33];
rcv_new=0;k=0;
STU[0].byte[2]=rcv_buf[2]; //放大器当前状态
STU[0].byte[3]=rcv_buf[3]; //错误标志
for(i=1;i<8;i++)
{
for(j=0;j<4;j++)
{
STU[i].byte[j]=rcv_buf[k+4];
k++;
}
}
for(i=0;i<8;i++)
{
sprintf(st[i],"%f",STU[i].fat);
}
}
// }
if(flag1==0)
{
flag1=1;
}
else
{
flag1=0;
}
if ( (IO1SET&LED) == 0 ) IO1SET |= LED;
else IO1CLR |= LED;
Time0_cnt++;
if(Time0_cnt>=3)
{
Time0_cnt=0;
command(0x66); //发送握手命令给DSP,读取放大器测量参数.
}
VICVectAddr = 0x00; // 通知VIC中断处理结束
}
//=================================================================================================
/**************************************************************************************************
Function: // void __irq IRQ_Timer1 (void)
Description: // for timer1 interrupt
Calls: // none
Called By: // init ()
Table Accessed: // none
Table Updated: // none
Input: // void
Output: // none
Return: // void
Others: // none
***************************************************************************************************/
uint16 t1_cnt;
void __irq IRQ_Timer1 (void)
{ //1ms定时
T1IR = 0x01; /* 清除中断标志 */
//----------------------------------------------
// if ( (IO1SET&LED) == 0 ) IO1SET = LED; // 控制LED4点亮
// else IO1CLR = LED; // 控制LED4熄灭
// ReadKey();// ReadKeyProcess();
t1_cnt++;
if(t1_cnt==3)
{
t1_cnt=0;
XAIOGUANDU++;
FENCHEN++;
TOUGUOLI++;
if(XAIOGUANDU>900) XAIOGUANDU=125;
if(FENCHEN>500) FENCHEN=30;
if(TOUGUOLI>800) TOUGUOLI=10;
}
if(flag2==0)
{
flag2=1;
}
else
{
flag2=0;
}
//-----------------------------------------------
VICVectAddr = 0x00; /* 通知VIC中断处理结束 */
}
//=================================================================================================
/**************************************************************************************************
Function: // void __irq IRQ_Eint0 (void)
Description: // for int0 interrupt
Calls: // none
Called By: // init ()
Table Accessed: // none
Table Updated: // none
Input: // void
Output: // none
Return: // void
Others: // none
***************************************************************************************************/
void __irq IRQ_Eint0 (void)
{
while ((EXTINT & 0x01) != 0)
{
EXTINT |= 0x01; // 清除EINT0中断标志
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -