|
#include "33A04.h"
void AiP33A04_Port_Init(void)
{
CLK = 0;
DIN = 0;
}
void AiP33A04_Write_Reg(unsigned char Current_Mode,unsigned char COM_Data,unsigned int SEG_Data)
{
unsigned char i;
/*傳輸16bit SEG數據*/
for(i=0;i<16;i++)
{
CLK = 0;
delay();
if(SEG_Data & 0x0001 == 0x0001)
DIN = 1;
else
DIN = 0;
delay();
CLK = 1;
delay();
SEG_Data = SEG_Data >> 1;
}
/*傳輸8bit COM數據*/
for(i=0;i<8;i++)
{
CLK = 0;
delay();
if(COM_Data & 0x01 == 0x01)
DIN = 1;
else
DIN = 0;
delay();
CLK = 1;
delay();
COM_Data=COM_Data>>1;
}
/*傳輸4bit 恒流選擇*/
for(i=0;i<4;i++)
{
CLK = 0;
delay();
if(Current_Mode & 0x1 == 0x1)
DIN = 1;
else
DIN = 0;
delay();
CLK = 1;
delay();
Current_Mode = Current_Mode>>1;
}
/*傳輸2bit保留位*/
for(i=0;i<2;i++)
{
CLK = 0;
delay();
DIN = 0;
delay();
CLK = 1;
delay();
}
}
void AiP33A04_Latch(void)
{
CLK = 1;
delay();
DIN = 1;
delay();
DIN = 0;
delay();
}
void AiP33A04_Stop(void)
{
CLK = 0;
delay();
DIN = 1;
delay();
DIN = 0;
delay();
}
void port_init()
{
P0IO = 0xFF; // direction
P0PU = 0x00; // pullup P1PU &= ~0x3f;
P0OD = 0x00; // open drain
P0DB = 0x00; // bit7~6(debounce clock), bit5~0=P07~02 debounce
P0 = 0x00; // port initial value
P1IO = 0xFF; // direction
P1PU = 0x00; // pullup
P1OD = 0x00; // open drain
P15DB = 0x00; // debounce : P54, 52, 17, 16, 12, 11
P1 = 0x00; // port initial value
P2IO = 0xFF; // direction
P2PU = 0x00; // pullup
P2OD = 0x00; // open drain
P2 = 0x00; // port initial value
P3IO = 0xFF; // direction
P3PU = 0x00; // pullup
P3 = 0x00; // port initial value
P4IO = 0xFF; // direction
P4PU = 0x00; // pullup
P4OD = 0x00; // open drain
P4 = 0x00; // port initial value
P5IO = 0xFF; // direction
P5PU = 0x00; // pullup
P5 = 0x00; // port initial value
// Set port functions
P0FSRH = 0x00; // P0 selection High
P0FSRL = 0x00; // P0 selection Low
P1FSRH = 0x00; // P1 selection High
P1FSRL = 0x00; // P1 selection Low
P2FSRH = 0x00; // P2 selection High
P2FSRL = 0x00; // P2 selection Low
P3FSR = 0x00; // P3 selection
P4FSR = 0x00; // P4 selection
P5FSR = 0x00; // P5 selection
}
#include "timer.h"
void Timer2_init()
{
// initialize Timer2
// T2ADRH = 0x07; T2ADRL = 0xcf; period = 1mS
// T2ADRH = 0x00; T2ADRL = 0xc7; period = 0.1mS
IE |= 0x80;
IE2 |= 0x08; // Enable Timer2 interrupt 定時器中斷使能
T2CRH |= 0x80; // timer setting High
T2CRL = 0x60; // timer setting Low8分頻
T2ADRH = 0x00; // period count High
T2ADRL = 0xc7; // period count Low
T2CRH |= 0x01; // timer setting High
}
void clock_init()
{
// internal RC clock (16.000000MHz)
OSCCR = 0x28; // Set Int. OSC
SCCR = 0x00; // Use Int. OSC
}
void INT_Timer2() interrupt 15
{
s=s-1;
}
|
-
-
304.zip
2024-9-12 19:11 上傳
點擊文件名下載附件
95.66 KB, 下載次數: 1
|