📄 level0.c
字号:
/* FileName: Level0.c */
#include "io51.h"
#include "usb_def.h"
/* the function defined in level0.c */
void write_host_addr(unsigned char addr);
void write_host_data(unsigned char datum);
unsigned char read_host_data(void);
void i_write_host_addr(unsigned char addr);
void i_write_host_data(unsigned char datum);
unsigned char i_read_host_data(void);
void enable_tmr(void);
void disable_tmr(void);
void delay ( unsigned int cnt);
void i_delay ( unsigned int cnt);
/* the external function defined in usb.c */
extern interrupt void T0_int(void);
extern interrupt void EX0_int(void);
extern void Dis_ver(void);
/**************************************************************************
This function write SL11H memory address to SL11H
**************************************************************************/
void write_host_addr(unsigned char addr)
{
P3.4=0; /* CS=0 */
P0= addr;
P1 &= 0xF9; /* WR=0,A0=0,RD=1 */
P1 &= 0xF9;
P1 |= 0x06; /* WR=1,A0=1,RD=1 */
}
/**************************************************************************
This function write data byte to SL11H memory
**************************************************************************/
void write_host_data(unsigned char datum)
{
P3.4=0; /* CS=0 */
P0 = datum;
P1 &= 0xFB; /* WR=0,A0=1,RD=1 */
P1 &= 0xFB;
P1 |= 0x04; /* WR=1,A0=1,RD=1 */
}
/**************************************************************************
This function read a byte from SL11H. It returns the byte read
**************************************************************************/
unsigned char read_host_data(void)
{
unsigned char read_data;
P0=0xFF;
P3.4=0; /* CS=0 */
P1 &= 0xF7; /* WR=1,A0=1,RD=0 */
P1 &= 0xF7;
read_data = P0;
P1 |= 0x08; /* WR=1,A0=1,RD=1 */
return read_data;
}
/**************************************************************************
This function write SL11H memory address to SL11H
**************************************************************************/
void i_write_host_addr(unsigned char addr)
{
P3.4=0; /* CS=0 */
P0 = addr;
P1.3=1; /* RD=1 */
P1 &= 0xF9; /* WR=0,A0=0,RD=1 */
P1 &= 0xF9;
P1 |= 0x06; /* WR=1,A0=1,RD=1 */
}
/**************************************************************************
This function write data byte to SL11H memory
**************************************************************************/
void i_write_host_data(unsigned char datum)
{
P3.4=0; /* CS=0 */
P0 = datum;
P1.1=1; P1.3=1; /* A0=1,RD=1 */
P1 &= 0xFB; /* WR=0,A0=1,RD=1 */
/* P1 &= 0xFB; */
P1 |= 0x04; /* WR=1,A0=1,RD=1 */
}
/**************************************************************************
This function read a byte from SL11H. It returns the byte read
**************************************************************************/
unsigned char i_read_host_data(void)
{
unsigned char read_data;
P0=0xFF;
P3.4=0; /* CS=0 */
P1.1=1; P1.2=1; /* A0=1,WR=1 */
P1 &= 0xF7; /* WR=1,A0=1,RD=0 */
/* P1 &= 0xF7; */
read_data = P0;
P1 |= 0x08; /* WR=1,A0=1,RD=1 */
return read_data;
}
/*************************************************************************
This function enables the 1 ms timer for sending EOF
The user should modify it according to the hardware
*************************************************************************/
void enable_tmr(void)
{
TR0=1; ET0 = 1;
}
/*************************************************************************
This function disables the 1 ms timer for sending EOF
The user should modify it according to the hardware
*************************************************************************/
void disable_tmr(void)
{
TR0=0; ET0 = 0;
}
/**************************************************************
File Name : void delay ( unsigned char count)
**************************************************************/
void delay ( unsigned int cnt)
{
unsigned int j;
for(j=0;j<cnt;j++);
}
/**************************************************************
File Name : void delay ( unsigned char count)
**************************************************************/
void i_delay ( unsigned int cnt)
{
unsigned int j;
for(j=0;j<cnt;j++);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -