📄 main.c
字号:
#include<ioaduc7020.h>
#include "common.h"
static unsigned char temp_counter; // Added by ADI as dummy variable
static unsigned char deviceadr=0xA2;
static unsigned char rtemp[8];
static unsigned char rcount=0;
static unsigned char i=0;
static unsigned long int status=0;
static unsigned char First;
//const long I2CDownloadKey @0x0014 =0x12345678;
//volatile __no_init const char xxxx @ 0x0014;
//const int gamma @ 0x0014 = 3; /* OK */
unsigned char A0[256];
unsigned char A2[256];
unsigned char Eeprom_User[128];
unsigned char DAC0_Tem_Table0[128];//reserved
unsigned char DAC0_Tem_Table1[128];//reserved
unsigned char DAC1_Tem_Table0[128];//ER
unsigned char DAC1_Tem_Table1[128];//ER
unsigned char DAC2_Tem_Table0[128];//Po
unsigned char DAC2_Tem_Table1[128];//Po
unsigned char DAC3_Tem_Table0[128];//APD
unsigned char DAC3_Tem_Table1[128];//APD
unsigned short PTRTemp;
unsigned char DACUpdateCounter;
unsigned char PW1[4];
unsigned char PW3[4];
unsigned char FlagPW1;
unsigned char FlagPW3;
unsigned int uiFIQSTA = 0;
unsigned int uiIRQSTA = 0;
__irq __arm void irq_handler(void); // IRQ Function Prototype
__irq __arm void fiq_handler();
unsigned char irq=0;
//sfpfloat dataRxCof[5];
void reset_display(void);
void lock_dead(void);
void reset_soft(void);
void initdevice(void);
void initvariable(void);
//void delay(unsigned int count);
void blinky(void);
void ADCpoweron(int);
int main(void)
{
initdevice();
initvariable();
// DACUpdate();
irq=0x00;
DACUpdateCounter=0x00;
FIQEN = 0x00000200; // enable i2c fiq
IRQEN = 0x00000008; // enable Timer1IRQ
while(1)
{
T3CLRI=0x00;//feed dog
if(irq==0x01)
{
// monitor();
// diag();
if(DACUpdateCounter>20) // updateDAC per 1S
{
DACUpdateCounter=0;
// DACUpdate();
}
irq=0x00;
}
/////////////////////////
/*
if(PW1Check()==0x01)
{
FlashControl();
DACControl();
}*/
}
}
void initdevice(void)
{
////OSC
POWKEY1 = 0x01;
POWCON = 0x00; //41.78MHz
// POWCON = 0x01; //20.89MHz
POWKEY2 = 0xF4;
delay(1000);
////Port
GP0CON = 0x00;
GP1CON = 0x22; // I2C on P1.0 and P1.1
GP4DAT = 0x04000000; // Configure P4.2 as output
////I2C
I2C0ID0 = 0xA0; // primary I2C address A0h
I2C0ID1 = 0xA2; // secondary I2C address A2h
I2C0ID2 = 0xA2; // secondary I2C address A2h
I2C0ID3 = 0xA2; // secondary I2C address A2h
I2C0CFG = 0x4001; // Enable I2C Slave mode and Interrupt Generation after Stop Condition
////Ref
REFCON = 0x01; // internal 2.5V reference. 2.5V on Vref pin
////DAC
DAC0CON = 0x12;
DAC1CON = 0x12;
DAC2CON = 0x12;
DAC3CON = 0x12;
////ADC
//ADCCON = 0x06A4; // ADC at default sampling frequency
// ADCCON = 0x0623;
ADCpoweron(200);
/////timer1
T1LD = 0x43; // Counter Value,20Hz,41.78MHz
T1CON= 0xCF; // count down ,periodic mode,binary format,CLK/32768
// T1LD = 0x10000; // Counter Value,20Hz,20.89MHz
// T1CON= 0xC4;
/////timer3 watchdog
//T3LD =0x0400;//4s
//T3CON= 0xA8;
/////Flash
}
void ADCpoweron(int time)
{
ADCCON = 0x20; // power-on the ADC
while (time >=0) // wait for ADC to be fully powered on
time--;
}
void initvariable(void)
{
unsigned int i;
i=0;
for(i=0;i<256;i++)
{
//A0[i]=flash_read(A0_Adr_Base+(i*2));
A0[i]=i;
//A2[i]=flash_read(A2_Adr_Base+(i*2));
A2[i]=255-i;
}
/* for(i=0;i<128;i++)
{
DAC0_Tem_Table0[i]=flash_read(DAC0_Adr_Base0+(i*2));
DAC0_Tem_Table1[i]=flash_read(DAC0_Adr_Base1+(i*2));
DAC1_Tem_Table0[i]=flash_read(DAC1_Adr_Base0+(i*2));
DAC1_Tem_Table1[i]=flash_read(DAC1_Adr_Base1+(i*2));
DAC2_Tem_Table0[i]=flash_read(DAC2_Adr_Base0+(i*2));
DAC2_Tem_Table1[i]=flash_read(DAC2_Adr_Base1+(i*2));
DAC3_Tem_Table0[i]=flash_read(DAC3_Adr_Base0+(i*2));
DAC3_Tem_Table1[i]=flash_read(DAC3_Adr_Base1+(i*2));
Eeprom_User[i]=flash_read(Eeprom_Adr_Base+(i*2));
A2[128+i]=Eeprom_User[i];
//A2[128+i]=0xA2;
DAC0_Tem_Table0[i]=0x80;
DAC0_Tem_Table1[i]=0x81;
DAC1_Tem_Table0[i]=0x82;
DAC1_Tem_Table1[i]=0x83;
DAC2_Tem_Table0[i]=0x84;
DAC2_Tem_Table1[i]=0x85;
DAC3_Tem_Table0[i]=0x86;
DAC3_Tem_Table1[i]=0x87;
}*/
for(i=200;i<256;i++)
{
A0[i]=0xFF;
}
//////////////// calibration cof DWDM
if(A0[0]==0x0B)
{
for(i=56;i<96;i++)
{A2[i]=0x00;}
}
/////////////// Calibration cof SFF-8472
//#ifdef SFF_8472
if(A0[0]==0x03)
{
for(i=56;i<68;i++)
{A2[i]=0x00;}////Rx_Cof(2)~Rx_Cof(3)=0.0
A2[68]=63; //// Rx_Cof(1)=1.0
A2[69]=128; //// Rx_Cof(1)=1.0
A2[70]=0; //// Rx_Cof(1)=1.0
A2[71]=0; //// Rx_Cof(1)=1.0
for(i=72;i<95;i++)
{A2[i]=0x00;}////Rx_Cof(0)=0.0
A2[76]=0x01;////Tx_I slope
//A2[77]=0x00;////Tx_I slope
//A2[78]=0x00;////Tx_I offset
//A2[79]=0x00;////Tx_I offset
A2[80]=0x01;////Tx_Pow slope
//A2[81]=0x00;////Tx_Pow slope
//A2[82]=0x00;////Tx_Pow offset
//A2[83]=0x00;////Tx_Pow offset
A2[84]=0x01;////Temperature slope
//A2[85]=0x00;////Temperature slope
//A2[86]=0x00;////Temperature offset
//A2[87]=0x00;////Temperature offset
A2[88]=0x01;////Vol slope
//A2[89]=0x00;////Vol slope
//A2[90]=0x00;////Vol offset
//A2[91]=0x00;////Vol offset
//A2[92]=0x00;////
//A2[93]=0x00;////
//A2[94]=0x00;////
}
//#endif
for(i=96;i<120;i++)
{A2[i]=0x00;}
A2[127]=0x01;///////////////////// page default 0x01
/* A0[63]=checksum0(0,62); ////checksum(0-94)
A0[95]=checksum0(64,94);////checksum(0-94)
A2[95]=checksum2(0,94); ////checksum(0-94)
for(i=0;i<=3;i++)
{
dataRxCof[0].ccof[i]=A0[160+3-i];
dataRxCof[1].ccof[i]=A0[156+3-i];
dataRxCof[2].ccof[i]=A0[152+3-i];
dataRxCof[3].ccof[i]=A0[148+3-i];
dataRxCof[4].ccof[i]=A0[142+3-i];
}*/
PW1[0]=2;
PW1[1]=0;
PW1[2]=0;
PW1[3]=8;
//PW2[0]=A0[176];
//PW2[1]=A0[177];
//PW2[2]=A0[178];
//PW2[3]=A0[179];
PW3[0]=A0[172];
PW3[1]=A0[173];
PW3[2]=A0[174];
PW3[3]=A0[175];
////////////////////////////////// Password entry
A0[252]=0x00;//PW1 Entry
A0[253]=0x00;//PW1 Entry
A0[254]=0x00;//PW1 Entry
A0[255]=0x00;//PW1 Entry
//A0[248]=0xFF;//PW2 Entry
//A0[249]=0xFF;//PW2 Entry
//A0[250]=0xFF;//PW2 Entry
//A0[251]=0xFF;//PW2 Entry
//A0[244]=0xFF;//PW3 Entry
//A0[245]=0xFF;//PW3 Entry
//A0[246]=0xFF;//PW3 Entry
//A0[247]=0xFF;//PW3 Entry
A2[123]=0xFF;//PW3 Entry
A2[124]=0xFF;//PW3 Entry
A2[125]=0xFF;//PW3 Entry
A2[126]=0xFF;//PW3 Entry
A2[127]=0x01;
////////////////////////////// Password change entry
A0[180]=0xFF;//PW1 change Entry
A0[181]=0xFF;//PW1 change Entry
A0[182]=0xFF;//PW1 change Entry
A0[183]=0xFF;//PW1 change Entry
A0[176]=0xFF;//PW2 change Entry
A0[177]=0xFF;//PW2 change Entry
A0[178]=0xFF;//PW2 change Entry
A0[179]=0xFF;//PW2 change Entry
A0[172]=0xFF;//PW3 change Entry
A0[173]=0xFF;//PW3 change Entry
A0[174]=0xFF;//PW3 change Entry
A0[175]=0xFF;//PW3 change Entry
// FlagPW1=PW1Check();
// FlagPW3=PW3Check();
}
void delay( int count)
{
while(--count)
;
}
void blinky(void)
{
GP4DAT ^= 0x00040000;
delay(10000);
}
__irq __arm void fiq_handler() {
uiFIQSTA = FIQSTA;
if ((uiFIQSTA & 0x200) == 0x200)
{
status = I2C0SSTA;
/***** Stop COndition *****/
if((status&0x400) == 0x400)
{
First = 0x01;
for(i=2;i<rcount+1;i++)
{
//////////////////////////////////////////////0xA0 Page
if(deviceadr==0xA0)
{
if(temp_counter>191)
{A0[temp_counter] = rtemp[i-2];}
if(FlagPW1)
{A0[temp_counter] = rtemp[i-2];}
}
////////////////////////////////////////////
if(deviceadr==0xA2)
{
A2[temp_counter] = rtemp[i-2];
}
temp_counter++;
}////////////for rcount
// I2C0FSTA |= 0x100; // Flush TXFIFO
rcount=0;
}/////////////////stop
/***** Slave TX **********/
if((status&0x4) == 0x4)
{
rcount=0;
if(deviceadr==0xA0)
{
I2C0STX = A0[temp_counter++];
}
///////////////////////////////////////
if(deviceadr==0xA2)
{
if(temp_counter<128)
{I2C0STX = A2[temp_counter++];}
}
//I2C0FSTA |= 0x100; // Flush TXFIFO
}
/***** Slave RX *****/
/* When A slave RX is generated, ISCxSRX must be read, otherwise an infinite Interrupt loop may occur*/
if((status&0x08) == 0x08)
{
rcount++;
if(rcount==1)
{
temp_counter=I2C0SRX;
}
if((rcount>1)&&(rcount<10))
{
rtemp[rcount-2]=I2C0SRX;
}
// ML added
if(deviceadr==0xA0)
{
I2C0STX = A0[temp_counter++];
}
///////////////////////////////////////
if(deviceadr==0xA2)
{
if(temp_counter<128)
{I2C0STX = A2[temp_counter++];}
}
//End ML
}
if(status&0x4000==0x4000)
{
if((status&0x00001800)==0x00000000)
{deviceadr=0xA0; }
else
{deviceadr=0xA2; }
}
}
if ((uiFIQSTA & 0x8)== 0x8)
{
GP4DAT ^= 0x00040000;
T1CLRI = 1; // Clear Timer IRQ
}
return;
}
__irq __arm void irq_handler() // example with two IRQs
{
uiIRQSTA = IRQSTA;
if ((uiIRQSTA & 0x8)== 0x8)
{
GP4DAT ^= 0x00040000;
T1CLRI = 1; // Clear Timer IRQ
}
// T1LD = 0x2000000; // Timer reload
// GP4DAT ^= 0x00040000;
// T1CLRI = 1; // Clear Timer IRQ
return;
}
__arm void undef_handler() // example with two IRQs
{
}
__arm void prefetch_handler() // example with two IRQs
{
}
__arm void data_handler() // example with two IRQs
{
}
/***************************************************************************************************************
Flash Adr A0[127] erase 0[214] write [219] RAM SIZE
#define A0_Adr_Base 0xF000 // 0xA0 0x33 0x33 A0 256
#define A2_Adr_Base 0xF200 // 0xA2 Table01h 0x44 0x44 A2 256
#define Eeprom_Adr_Base 0xF400 // 0xEep table01h 0x55 0x55 UEep 128
#define DAC0_Adr_Base0 0xDC00 //DAC0 table80h 0x66 0x66 reserved 128
#define DAC0_Adr_Base1 0xE000 //DAC0 table81h 0x77 0x77 reserved 128
#define DAC1_Adr_Base0 0xE200 //DAC1 table82h 0x88 0x88 ER 128
#define DAC1_Adr_Base1 0xE400 //DAC1 table83h 0x99 0x99 ER 128
#define DAC2_Adr_Base0 0xE600 //DAC2 table84h 0xAA 0xAA Po 128
#define DAC2_Adr_Base1 0xE800 //DAC2 table85h 0xBB 0xBB Po 128
#define DAC3_Adr_Base0 0xEA00 //DAC3 table86h 0xCC 0xCC APD 128
#define DAC3_Adr_Base1 0xEC00 //DAC3 table87h 0xDD 0xDD APD 128
***************************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -