📄 main.c
字号:
#include <c8051f320.h> // SFR declarations
#include "usb_api.h"
sbit SDA = P2^2 ;
sbit SCL = P2^3 ;
sbit LED = P0^7; // LED='1' means ON
void Init_Sysclock (void);
void Init_Port (void);
void Ext_Interrupt_Init (void);
//-----------------------------------------------------------------------------
// Global VARIABLES
//-----------------------------------------------------------------------------
extern void Dab_Read_Register(int reg_addr,int *ptrdata);
extern void Dab_Write_Register(int reg_addr,int reg_data);
/*** [BEGIN] USB Descriptor Information [BEGIN] ***/
code const UINT USB_VID = 0x10C4;
code const UINT USB_PID = 0xEA61;
code const BYTE USB_MfrStr[] = {0x1A,0x03,'S',0,'i',0,'l',0,'i',0,'c',0,'o',0,'n',0,' ',0,'L',0,'a',0,'b',0,'s',0}; // Manufacturer String
code const BYTE USB_ProductStr[] = {0x10,0x03,'U',0,'S',0,'B',0,' ',0,'A',0,'P',0,'I',0}; // Product Desc. String
code const BYTE USB_SerialStr[] = {0x0A,0x03,'Z',0,'h',0,'o',0,'u',0};
code const BYTE USB_MaxPower = 15; // Max current = 30 mA (15 * 2)
code const BYTE USB_PwAttributes = 0x80; // Bus-powered, remote wakeup not supported
code const UINT USB_bcdDevice = 0x0100; // Device release number 1.00
/*** [ END ] USB Descriptor Information [ END ] ***/
unsigned char access_data_stream;
BYTE usb_write_flag;
xdata unsigned char command_packet[8];
xdata BYTE buffer_storage[512];
extern void DabFM_Init(void);
void main (void) {
int i;
PCA0MD &= ~0x40; // WDTE = 0 (Disable watchdog timer)
CLKMUL = 0x80;
for (i = 0; i < 200; i++); // Wait 5us for initialization
CLKMUL |= 0xC0;
while ((CLKMUL & 0x20) == 0);
CLKSEL = 0x02;
OSCICN = 0x83;
Init_Port();
USB_Clock_Start(); // Init USB clock *before* calling USB_Init
USB_Init(USB_VID,USB_PID,USB_MfrStr,USB_ProductStr,USB_SerialStr,USB_MaxPower,USB_PwAttributes,USB_bcdDevice);
CLKSEL|=0x02;
USB_Int_Enable();
EA=0;
Ext_Interrupt_Init();
EA=1;
//DabFM_Init();
for(;;) { // spin forever
if(access_data_stream==1)
{
if(usb_write_flag == 1) // half of fifo
{
usb_write_flag=0;
Block_Write(buffer_storage, 512);
}
}
}//end for(;;);
}
//-----------------------------------------------------------------------------
// Ext_Interrupt_Init
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters : None
//
// This function configures and enables /INT0 (External Interrupts)
// as negative edge-triggered.
//
//-----------------------------------------------------------------------------
void Ext_Interrupt_Init(void)
{
TCON=0x00;//INT 0 level triggered
IT01CF = 0x06;//P0.6作为外部中断INT0 active low;
EX0 = 1; // Enable /INT0 interrupts
}
//-----------------------------------------------------------------------------
// Init_Port
//
// Configure the Crossbar and GPIO ports.
//
//
//-----------------------------------------------------------------------------
void Init_Port (void)
{
P0MDOUT = 0xbf;//
//P2MDOUT = 0x0C;
//P0MDOUT = 0xff;//
//////////////////////
P1MDIN= 0xff; // pins on P1 are digital
//十个并口线全部push-pull
P1MDOUT=0x00;
P1=0xff;
P2MDOUT=0x03;
//////////////////////////
P0SKIP = 0xcc;//
P1SKIP = 0xFF;
P2SKIP = 0x0F;//P2.0---P2.3 skip
///important
XBR0 = 0x06;//p0.6跳过。分配为中断脚
XBR1 = 0x40;
//-----------------------------------------------------------------------------
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -