📄 kanmen.c
字号:
// 3. AT89C2051和X25045的初始化程序:
#include <REG51.H> /* special function register declarations */
/* for the intended AT89C2051 derivative */
#include <stdio.h> /* prototype declarations for I/O functions */
#ifdef MONITOR51 // Debugging with Monitor-51 needs
char code reserve [3] _at_ 0x23; // space for serial interrupt if
#endif // Stop Exection with Serial Intr.
sbit P1_1=P1^1; /* SI connect to P1^1 */
sbit P3_4=P3^4; /* SCK connect to P3^4 */
sbit P3_5=P3^5; //when running this program, /WP is high
void timer0 (void) interrupt 1 using 2 //define timer0 interrupt
{ P3_4=!P3_4;}
void timer1 (void) interrupt 3 using 2 //define timer1 interrupt
{do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=1;
do{}while(P3_4!=0||!TF0);
P1_1=1;
do{}while(P3_4!=0||!TF0);
P1_1=0; //WREN instruciton:00000110B
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=1;
do{}while(P3_4!=0||!TF0);
P1_1=0; //Write instruction:00000010B
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=1;
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=0;
do{}while(P3_4!=0||!TF0);
P1_1=1;
do{}while(P3_4!=0||!TF0);
P1_1=1;
//WD1=1,WD0=0,RESET time is 200ms, BL1=0,BL0=0,no block
//protect,STATUS_REG:00100000B
}
void main (void) {
P3_5=0; // enable /CS
/* setup the timer 0 interrupt */
TH0 = 0xFF; // set timer period; t is 10 us; set the frequency of sclk is 50khz
TL0 = 0xF6;
TMOD = TMOD | 0x11; // select mode 1
TR0 = 1; // start timer 0
ET0 = 1; // enable timer 0 interrupt
EA = 1; // global interrupt enable
/* setup the timer 1 interrupt */
TH1 = 0x28; // set timer period ; feed dog time is 60 ms
TL1 = 0x00;
TMOD = TMOD | 0x11; // select mode 1
TR1 = 1; // start timer 1
ET1 = 1; // enable timer 1 interrupt
EA = 1; // global interrupt enable
do{}while(!TF0&&!TF1); //wait for timer0 interrupt or timer 1 interrupt
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -