?? max525._c
字號:
//ICC-AVR application builder : 2007-8-11 14:36:41
// Target : M16
// Crystal: 16.000Mhz
#include <iom16v.h>
#include <macros.h>
#include <delay.h>
///////////////////////硬件接口/////////////////
#define DDR DDRA
#define PORT PORTA
#define PIN PINA
///////////////////控制////////////////////////
#define CS_525 0
#define DIN_525 1
#define SCLK_525 2
#define SETBIT(x,y) (x|=(1<<y)) //set bit y in byte x
#define CLRBIT(x,y) (x&=(~(1<<y))) //clear bit y in byte x
#define CHKBIT(x,y) (x&(1<<y)) //check bit y in byte x
///////////////////////////////////////////////
#define Reg_Unchanged 0x0D
#define Reg_Updated 0X0f
#define Start_Up_Reg 0x04
#define Start_Up_Load 0x08
#define Shutdown 0x0c
//#define Mode_1 0x0e
//#define Mode_2 0x0a
//////////////////////////////////////////////
void Sent_to_max525(unsigned char Addr,int Data)
{
unsigned char i,j;//temp;
CLRBIT(PORT,CS_525); //CS=0
//CLRBIT(PORT,SCLK_525);
//SETBIT(PORT,SCLK_525);
////////////////////////////////////////////////
for (i=0;i<4;i++) //傳地址4位
{
CLRBIT(PORT,SCLK_525);
if(Addr&0x08)
SETBIT(PORT,DIN_525);
else
CLRBIT(PORT,DIN_525);
SETBIT(PORT,SCLK_525);
//CLRBIT(PORT,SCLK_525);
Addr=Addr<<1;
}
/////////////////////////////////////////////////////
for (j=0;j<12;j++) //傳數據12位
{
CLRBIT(PORT,SCLK_525);
if(Data&0x0800)
SETBIT(PORT,DIN_525);
else
CLRBIT(PORT,DIN_525);
SETBIT(PORT,SCLK_525);
Data=Data<<1;
}
SETBIT(PORT,SCLK_525);
delay_nus(50);
CLRBIT(PORT,SCLK_525);
SETBIT(PORT,CS_525); //CS=1
}
///////////////////////////////////////////////////////
void port_init(void)
{
PORTA = 0xff;
DDRA = 0xff;
PORTB = 0xff;
DDRB = 0xff;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void main()
{
// unsigned char i,Addr=0xaA;
init_devices();
//CLI();
Sent_to_max525(0x04,0x000);
while(1)
{
//Sent_to_max525(0x08,0x0);
Sent_to_max525(0x0f,0xfff);
//Sent_to_max525(0x0f,0x000);
// Sent_to_max525(0x0f,0xfff);
//Sent_to_max525(0x0f,0xfff);
// Sent_to_max525(0x0f,0xFFF);
//(0x0f,0x0FFF);
//delay_nms(100);
//Sent_to_max525(0x0f,0x0000);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -