📄 timer_isr.c
字号:
// next state
sccb_state = SCCB_XMT_CLK;
*pTIMER_STATUS = 0x0011;
break;
case SCCB_XMT_CLK:
// set SCL high
*pFIO_FLAG_S = SCL;
// next state
sccb_state = SCCB_Xmt_Data;
*pTIMER_STATUS = 0x0011;
break;
case SCCB_ACK_TST:
// drive SCL high
*pFIO_FLAG_S = SCL;
//Check SDA input. It must be low at this point
if(*pFIO_FLAG_S & SDA)
{
//something is wrong
asm("emuexcpt;");
}
// next state
sccb_state = SCCB_ACK_MNGR;
*pTIMER_STATUS = 0x0011;
break;
case SCCB_ACK_MNGR:
/*************** SCCB SCCB Taskmanger routine********************************************/
//The Taskmanager handles the different use of the interface. It can be written to the
//device or read from the device. Up to sixty bytes (can be changed) can be written to
//or read from the device. Finishing the data transfer links to the stop condition.
// toggle SCL to low
*pFIO_FLAG_C = SCL;
// modify the word count
SCCB_Word_Count--;
if(SCCB_Word_Count==0)
{
//SCCB_Xfer_Done
//configure SDA as output
*pFIO_DIR |= SDA;
// change SDA to input
*pFIO_INEN &= (~SDA);
// drive SDA low
*pFIO_FLAG_C = SDA;
// next state
sccb_state = SCCB_Stop_Cond1;
*pTIMER_STATUS = 0x0011;
break;
}
// re-load the bit count (byte finished)
SCCB_Bit_Count = 0x8;
//"1" = read; "2" = write
if(SCCB_Control==2)
{
//SCCB_Write_Task
while(1)
{
// wait for SDA to go hi (tri-state)
if(*pFIO_FLAG_C & SDA)
{
break;
}
}
//configure SDA as output
*pFIO_DIR |= SDA;
// change SDA to input
*pFIO_INEN &= (~SDA);
// check SCCB_Read_Count
if(SCCB_Read_Count==0)
{
//SCCB_Prepare_Start
// drive SDA high
*pFIO_FLAG_S = SDA;
// next state
sccb_state = SCCB_Start_Cond0;
}else
{
// next state
sccb_state = SCCB_Xmt_Data;
pSCCB_Data_Pointer++;
SCCB_Write_Read_Register = *pSCCB_Data_Pointer;
}
*pTIMER_STATUS = 0x0011;
break;
}
if(SCCB_Read_Count==0)
{
// jump after first 3 bytes got sent
//SCCB_Read1_Task
SCCB_Read_Count = 3;
//Get the data to send
SCCB_Write_Read_Register = 0;
pSCCB_Data_Pointer = SCCB_DataOut;
}
if(SCCB_Read_Count==3)
{
// make sure SDA is configured as input
*pFIO_DIR &= (~SDA);
// change SDA to input
*pFIO_INEN |= SDA;
// next state
sccb_state = SCCB_RCV_CLK;
}
SCCB_Read_Count--;
*pTIMER_STATUS = 0x0011;
break;
case SCCB_RCV_CLK:
/*************** SCCB Receive Clock Test routine******************/
// set SCL hi
*pFIO_FLAG_S = SCL;
// next state
sccb_state = SCCB_Rcv_Data;
*pTIMER_STATUS = 0x0011;
break;
case SCCB_Stop_Cond1:
/*************** SCCB Stop Cond1 ****************************/
// drive SCL hi
*pFIO_FLAG_S = SCL;
// next state
sccb_state = SCCB_Stop_Cond2;
*pTIMER_STATUS = 0x0011;
break;
case SCCB_Stop_Cond2:
/*************** SCCB Stop Cond2 ****************************************/
// drive SDA high
*pFIO_FLAG_S = SDA;
// next state
sccb_state = SCCB_End_of_Transmission;
*pTIMER_STATUS = 0x0011;
break;
case SCCB_NACK_TST:
// drive SCL high
*pFIO_FLAG_S = SCL;
//Check SDA input. It must be hi at this point
if(~(*pFIO_FLAG_S & SDA))
{
//If not, something is wrong
asm("emuexcpt;");
}
// next state
sccb_state = SCCB_ACK_MNGR;
*pTIMER_STATUS = 0x0011;
break;
case SCCB_Rcv_Data:
//Get the current rcv byte
SCCB_Write_Read_Register = SCCB_Write_Read_Register << 1; //shift to point to the next bit
//Check the SDA bit.
if(*pFIO_FLAG_S & SDA)
{
//SCCB_Rcv_Bit_Hi
//set bit #0
SCCB_Write_Read_Register |= 0x1;
}else
{
//clear bit #0
SCCB_Write_Read_Register &= 0xFFFFFFFE;
}
// update the bit count
SCCB_Bit_Count--;
// check if it was the last bit
if(SCCB_Bit_Count==0)
{
// SCCB_Rcv_Byte_Done
/////???????????????????????????????????
//save the shifted byte for the run
pSCCB_Data_Pointer = &SCCB_Write_Read_Register;
//Increment the pointer to the data array
pSCCB_Data_Pointer++;
SCCB_Write_Read_Register = *pSCCB_Data_Pointer;
// save the received byte
pSCCB_Data_Pointer = &SCCB_Write_Read_Register;
// drive SCL low
*pFIO_FLAG_C = SCL;
// wait for SDA to go hi (tri-state)
while(1)
{
if(*pFIO_FLAG_C & SDA)
{
break;
}
}
// change SDA to input
*pFIO_INEN &= (~SDA);
//configure SDA as output
*pFIO_DIR |= SDA;
// check if last byte
if(SCCB_Word_Count==1)
{
//SCCB_RCV_NACK
// drive SDA high
*pFIO_FLAG_S = SDA;
// next state
sccb_state = SCCB_NACK_TST;
}else{
// drive SDA low
*pFIO_FLAG_C = SDA;
// next state
sccb_state = SCCB_ACK_TST;
}
}else{
// drive SCL low
*pFIO_FLAG_C = SCL;
// next state
sccb_state = SCCB_RCV_CLK;
}
*pTIMER_STATUS = 0x0011;
break;
case SCCB_RCV_NACK:
// drive SDA high
*pFIO_FLAG_S = SDA;
// next state
sccb_state = SCCB_NACK_TST;
*pTIMER_STATUS = 0x0011;
break;
case SCCB_End_of_Transmission:
/*************** SCCB Stop Cond2 ****************************************/
//The transmission ends and all the timer settings must be diabled
//This would be a good place to set a bit to replay the transfer is done
//disable the timer clear interrupt bit and overflow bit
*pTIMER_STATUS = 0x1011;
//disable mask the Timer0 again, clear bit #16
*pSIC_IMASK &= ~IRQ_TIMER0;
// clear SCCB_Read_Count (end of transfer flag, EOT)
SCCB_Read_Count = 0xab; // EOT flag value
// *pTIMER_STATUS = 0x0011;
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -