?? main.c
字號:
#include "44b0.h"
void ini_io(void);
void ini_IIC(void);
void ini_memory(void);
void ini_pllclock(void); //函數聲明
//***************************************************
void ini_io()
{
rPCONF=0x0a;//PF0,PF1配置為IIC bus的時鐘和數據
rPUPF=0x03;//禁止內部上拉
rPCONC=0x54;
}
//****************************************************
void ini_memory()//存儲體配置
{
rBWSCON=0x11001100;
rBANKCON6=0x18000;
rBANKCON7=0x18000;
rREFRESH=(8<<20)+(4<<16)+1049;
rBANKCON0=0x7ff0;
rBANKCON1=0x7ff0;
rBANKCON2=0x7ff0;
rBANKCON3=0x7ff0;
rBANKCON4=0x7ff0;
rBANKCON5=0x7ff0;
}
//*****************************************************
void ini_pllclock()//時鐘設置
{
rLOCKTIME=0xfff;//默認值
rPLLCON=(88<<12)|(4<<4)|2;
rCLKCON=0x7ff8;//Fout=40MHZ
}
//*****************************************************
void ini_IIC()
{
rIICCON=0xaf;//IIC bus時鐘速率為156250Hz,禁止中斷
}
//******************************************************
int main()
{
unsigned table[16];
unsigned int i=100000;
char buffer;
ini_memory();
ini_pllclock();
ini_io();
ini_IIC();
rINTMSK=0x7ffffff;//屏蔽所有中斷
//*****************AT24C08字節寫8個字節*******************
rIICDS=0xa0;
rIICSTAT=0xf0;//產生起始位并發送從機地址
while((rIICCON&0x10)==0);
rIICDS=0x10;//準備向地址為0x10的單元寫入數據
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICDS=0x0c;//寫入數據0x0c
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICSTAT=0xd0;//產生停止位
rIICCON=0xaf;
while(i--);
i=100000;
rIICDS=0xa0;
rIICSTAT=0xf0;//產生起始位并發送從機地址
while((rIICCON&0x10)==0);
rIICDS=0x11;//準備向地址為0x11的單元寫入數據
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICDS=0x02;//寫入數據0x02
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICSTAT=0xd0;//產生停止位
rIICCON=0xaf;
while(i--);
i=100000;
rIICDS=0xa0;
rIICSTAT=0xf0;//產生起始位并發送從機地址
while((rIICCON&0x10)==0);
rIICDS=0x12;//準備向地址為0x12的單元寫入數據
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICDS=0x04;//寫入數據0x04
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICSTAT=0xd0;//產生停止位
rIICCON=0xaf;
while(i--);
i=100000;
rIICDS=0xa0;
rIICSTAT=0xf0;//產生起始位并發送從機地址
while((rIICCON&0x10)==0);
rIICDS=0x13;//準備向地址為0x13的單元寫入數據
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICDS=0x06;//寫入數據0x06
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICSTAT=0xd0;//產生停止位
rIICCON=0xaf;
while(i--);
i=100000;
rIICDS=0xa0;
rIICSTAT=0xf0;//產生起始位并發送從機地址
while((rIICCON&0x10)==0);
rIICDS=0x14;//準備向地址為0x14的單元寫入數據
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICDS=0x08;//寫入數據0x08
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICSTAT=0xd0;//產生停止位
rIICCON=0xaf;
while(i--);
i=100000;
rIICDS=0xa0;
rIICSTAT=0xf0;//產生起始位并發送從機地址
while((rIICCON&0x10)==0);
rIICDS=0x15;//準備向地址為0x15的單元寫入數據
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICDS=0x0a;//寫入數據0x0a
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICSTAT=0xd0;//產生停止位
rIICCON=0xaf;
while(i--);
i=100000;
rIICDS=0xa0;
rIICSTAT=0xf0;//產生起始位并發送從機地址
while((rIICCON&0x10)==0);
rIICDS=0x16;//準備向地址為0x16的單元寫入數據
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICDS=0x0c;//寫入數據0x0c
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICSTAT=0xd0;//產生停止位
rIICCON=0xaf;
while(i--);
i=100000;
rIICDS=0xa0;
rIICSTAT=0xf0;//產生起始位并發送從機地址
while((rIICCON&0x10)==0);
rIICDS=0x17;//準備向地址為0x17的單元寫入數據
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICDS=0x0e;//寫入數據0x0e
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICSTAT=0xd0;//產生停止位
rIICCON=0xaf;
while(i--);
//******************AT24C08隨機讀8個字節操作****************
rIICDS=0xa0;
rIICSTAT=0xf0;
while((rIICCON&0x10)==0);
rIICDS=0x10;//讀地址0x10的數據
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICCON=0xaf;
rIICDS=0xa1;
rIICSTAT=0xb0;
while((rIICCON&0x10)==0);
buffer=rIICDS;
rIICCON=0x2f;
while((rIICCON&0x10)==0);
buffer=rIICDS;
rIICSTAT=0x90;
rIICCON=0xaf;
i=100000;
while(i--);
rPDATC=buffer;
i=10000000;
while(i--);
rIICDS=0xa0;
rIICSTAT=0xf0;
while((rIICCON&0x10)==0);
rIICDS=0x11;//讀地址0x11的數據
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICCON=0xaf;
rIICDS=0xa1;
rIICSTAT=0xb0;
while((rIICCON&0x10)==0);
buffer=rIICDS;
rIICCON=0x2f;
while((rIICCON&0x10)==0);
buffer=rIICDS;
rIICSTAT=0x90;
rIICCON=0xaf;
i=100000;
while(i--);
rPDATC=buffer;
i=10000000;
while(i--);
rIICDS=0xa0;
rIICSTAT=0xf0;
while((rIICCON&0x10)==0);
rIICDS=0x12;//讀地址0x12的數據
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICCON=0xaf;
rIICDS=0xa1;
rIICSTAT=0xb0;
while((rIICCON&0x10)==0);
buffer=rIICDS;
rIICCON=0x2f;
while((rIICCON&0x10)==0);
buffer=rIICDS;
rIICSTAT=0x90;
rIICCON=0xaf;
i=100000;
while(i--);
rPDATC=buffer;
i=10000000;
while(i--);
rIICDS=0xa0;
rIICSTAT=0xf0;
while((rIICCON&0x10)==0);
rIICDS=0x13;//讀地址0x13的數據
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICCON=0xaf;
rIICDS=0xa1;
rIICSTAT=0xb0;
while((rIICCON&0x10)==0);
buffer=rIICDS;
rIICCON=0x2f;
while((rIICCON&0x10)==0);
buffer=rIICDS;
rIICSTAT=0x90;
rIICCON=0xaf;
i=100000;
while(i--);
rPDATC=buffer;
i=10000000;
while(i--);
rIICDS=0xa0;
rIICSTAT=0xf0;
while((rIICCON&0x10)==0);
rIICDS=0x14;//讀地址0x14的數據
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICCON=0xaf;
rIICDS=0xa1;
rIICSTAT=0xb0;
while((rIICCON&0x10)==0);
buffer=rIICDS;
rIICCON=0x2f;
while((rIICCON&0x10)==0);
buffer=rIICDS;
rIICSTAT=0x90;
rIICCON=0xaf;
i=100000;
while(i--);
rPDATC=buffer;
i=10000000;
while(i--);
rIICDS=0xa0;
rIICSTAT=0xf0;
while((rIICCON&0x10)==0);
rIICDS=0x15;//讀地址0x15的數據
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICCON=0xaf;
rIICDS=0xa1;
rIICSTAT=0xb0;
while((rIICCON&0x10)==0);
buffer=rIICDS;
rIICCON=0x2f;
while((rIICCON&0x10)==0);
buffer=rIICDS;
rIICSTAT=0x90;
rIICCON=0xaf;
i=100000;
while(i--);
rPDATC=buffer;
i=10000000;
while(i--)
rIICDS=0xa0;
rIICSTAT=0xf0;
while((rIICCON&0x10)==0);
rIICDS=0x16;//讀地址0x16的數據
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICCON=0xaf;
rIICDS=0xa1;
rIICSTAT=0xb0;
while((rIICCON&0x10)==0);
buffer=rIICDS;
rIICCON=0x2f;
while((rIICCON&0x10)==0);
buffer=rIICDS;
rIICSTAT=0x90;
rIICCON=0xaf;
i=100000;
while(i--);
rPDATC=buffer;
i=10000000;
while(i--);
rIICDS=0xa0;
rIICSTAT=0xf0;
while((rIICCON&0x10)==0);
rIICDS=0x17;//讀地址0x17的數據
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICCON=0xaf;
rIICDS=0xa1;
rIICSTAT=0xb0;
while((rIICCON&0x10)==0);
buffer=rIICDS;
rIICCON=0x2f;
while((rIICCON&0x10)==0);
buffer=rIICDS;
rIICSTAT=0x90;
rIICCON=0xaf;
i=100000;
while(i--);
rPDATC=buffer;
i=10000000;
while(i--);
//*********************頁寫方式從地址0x1c0開始寫入16個字節***************************
rIICCON=0xaf;//恢復應答使能并清中斷標志位
rIICDS=0xa2;
rIICSTAT=0xf0;//產生起始位并發送從機地址
while((rIICCON&0x10)==0);
rIICDS=0xc0;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICDS=0x0c;//向地址為0x1c0的單元寫入數據0x0c
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICDS=0x0e;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICDS=0x0a;
rIICCON=0xa9;
while((rIICCON&0x10)==0);
rIICDS=0x08;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICDS=0x06;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICDS=0x04;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICDS=0x02;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICDS=0x0c;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICDS=0x0e;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICDS=0x06;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICDS=0x0a;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICDS=0x08;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICDS=0x02;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICDS=0x04;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICDS=0x0c;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICDS=0x0e;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICSTAT=0xd0;//產生停止位
rIICCON=0xaf;
i=1000000;
while(i--);
//*****************順序讀出頁方式寫入的16個字節***************
rIICDS=0xa2;
rIICSTAT=0xf0;
while((rIICCON&0x10)==0);
rIICDS=0xc0;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
rIICCON=0xaf;
rIICDS=0xa3;
rIICSTAT=0xb0;
while((rIICCON&0x10)==0);
buffer=rIICDS;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
table[0]=rIICDS;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
table[1]=rIICDS;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
table[2]=rIICDS;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
table[3]=rIICDS;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
table[4]=rIICDS;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
table[5]=rIICDS;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
table[6]=rIICDS;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
table[7]=rIICDS;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
table[8]=rIICDS;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
table[9]=rIICDS;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
table[10]=rIICDS;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
table[11]=rIICDS;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
table[12]=rIICDS;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
table[13]=rIICDS;
rIICCON=0xaf;
while((rIICCON&0x10)==0);
table[14]=rIICDS;
rIICCON=0x2f;
while((rIICCON&0x10)==0);
table[15]=rIICDS;
rIICSTAT=0x90;
rIICCON=0xaf;
i=100000;
while(i--);
//***********顯示頁寫入的數據****************
while(1)
{
rPDATC=table[0];
i=10000000;
while(i--);
rPDATC=table[1];
i=10000000;
while(i--);
rPDATC=table[2];
i=10000000;
while(i--);
rPDATC=table[3];
i=10000000;
while(i--);
rPDATC=table[4];
i=10000000;
while(i--);
rPDATC=table[5];
i=10000000;
while(i--);
rPDATC=table[6];
i=10000000;
while(i--);
rPDATC=table[7];
i=10000000;
while(i--);
rPDATC=table[8];
i=10000000;
while(i--);
rPDATC=table[9];
i=10000000;
while(i--);
rPDATC=table[10];
i=10000000;
while(i--);
rPDATC=table[11];
i=10000000;
while(i--);
rPDATC=table[12];
i=10000000;
while(i--);
rPDATC=table[13];
i=10000000;
while(i--);
rPDATC=table[14];
i=10000000;
while(i--);
rPDATC=table[15];
i=10000000;
while(i--);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -