/* 文件:AVR_PQ1A.H 功能:定义一些AVR_PQ1A开发板上应用程序用到的常量 // #include//包含型号头文件 #include //包含"位"操作头文件 /数据类型宏定义/ #define uchar unsigned char #define uint unsigned int /数码管和LED常量/ #define LEDLK PA2 //LED锁存器控制端 #define SEGLK PA3 //数码管段选锁存器控制端 #define BITLK PA4 //数码管位选锁存器控制端 #define TRUE 1 #define FALSE 0 #define ALLLED 0XFF /* 函数名称: Delayus 功 能: 延时指定微秒(8M晶振) 参 数: US--延时的微秒数(大约,不是很精确,MS越大越准确) 返回值 : 无 // void Delayus(uint US) { uint i; US=US*5/4; //5/4是在8MHz晶振下,通过软件仿真反复实验得到的数值 for( i=0;i 1010 or DS=00 or RS=00) //RAM 命令 #define C_RAMBASE 0xC0 //RAM0~RAM30<<1 地址需左移一位 /USB常量/ #define CSUSB PA7 #define D12_INT PD3 #define WR_N PD4 #define RD_N PD5 #define C_D PD6 #define D12_CS PD7 #define USBCTL_DDR DDRD #define USBCTL_PORT PORTD #define USBDAT_DDR DDRB #define USBDAT_PORT PORTB #define USBDAT_PIN PINB #define CMD 0x01 #define DAT 0x00 #define UEN_GINT() SREG&=~BIT(7) #define EN_GINT() SREG|=BIT(7) #define MSB(x) (((x) >> 8) & 0xFF) #define MAX_ENDPOINTS (uchar)0x3 #define NOLAZYCLOCK 0x02 #define CLOCKRUNNING 0x04 #define INTERRUPTMODE 0x08 #define SOFTCONNECT 0x10 #define ENDP_NONISO 0x00 #define ENDP_ISOOUT 0x40 #define ENDP_ISOIN 0x80 #define ENDP_ISOIO 0xC0 #define CLOCK_12M 0x03 #define CLOCK_4M 0x0b #define SETTOONE 0x40 #define SOFONLY 0x80 #define NORMALPLUSSOF 0x20 #define ENDP4INTENABLE 0x40 #define ENDP5INTENABLE 0x80 #define INT_ENDP0OUT 0x01 #define INT_ENDP0IN 0x02 #define INT_ENDP1OUT 0x04 #define INT_ENDP1IN 0x08 #define INT_ENDP2OUT 0x10 #define INT_ENDP2IN 0x20 #define INT_BUSRESET 0x40 #define INT_SUSPENDCHANGE 0x80 #define SETUPPACKET 0x20 #define BUFFER0FULL 0x20 #define BUFFER1FULL 0x40 #define FULLEMPTY 0x01 #define STALL 0x02 #define USB_IDLE 0 #define USB_TRANSMIT 1 #define USB_RECEIVE 2 #define MAX_CTLDAT_SIZE 8 #define USB_ENDPOINT_DIRECTION_MASK 0x80 #define USB_REQUEST_MASK (uchar)0x0F #define USB_REQUEST_TYPE_MASK (uchar)0x60 #define USB_STANDARD_REQUEST (uchar)0x00 #define DEVICE_ADDRESS_MASK 0x7F #define USB_FEATURE_ENDPOINT_STALL (uint)0x0000 #define USB_FEATURE_REMOTE_WAKEUP (uint)0x0001 #define EP0_PACKET_SIZE 16 #define EP1_PACKET_SIZE 16 #define EP2_PACKET_SIZE 64 #define USB_RECIPIENT (uchar)0x1F #define USB_RECIPIENT_DEVICE (uchar)0x00 #define USB_RECIPIENT_INTERFACE (uchar)0x01 #define USB_RECIPIENT_ENDPOINT (uchar)0x02 #define USB_DEVICE_DESCRIPTOR_TYPE 0x01 #define USB_CONFIGURATION_DESCRIPTOR_TYPE 0x02 #define USB_STRING_DESCRIPTOR_TYPE 0x03 #define USB_INTERFACE_DESCRIPTOR_TYPE 0x04 #define USB_ENDPOINT_DESCRIPTOR_TYPE 0x05 #define USB_POWER_DESCRIPTOR_TYPE 0x06 /* 设备描述符: 测试设备类型 */ #define USB_CLASS_CODE_TEST_CLASS_DEVICE 0xdc /* D12 配置描述符长度 / #define CONFIG_DESCRIPTOR_LENGTH sizeof(USB_CONFIGURATION_DESCRIPTOR) \ + sizeof(USB_INTERFACE_DESCRIPTOR) \ + (NUM_ENDPOINTS * sizeof(USB_ENDPOINT_DESCRIPTOR)) /* D12 接口描述符中: 除端点0的端点索引数目 / #define NUM_ENDPOINTS 4 /* 设备描述符: 测试设备类型 */ #define USB_CLASS_CODE_TEST_CLASS_DEVICE 0xdc /* 接口描述符: 子类代码 */ #define USB_SUBCLASS_CODE_TEST_CLASS_D12 0xA0 /* 接口描述符: 协议代码 */ #define USB_PROTOCOL_CODE_TEST_CLASS_D12 0xB0 /* USB 端点描述符结构体: 端点属性 / #define USB_ENDPOINT_TYPE_MASK 0x03 #define USB_ENDPOINT_TYPE_CONTROL 0x00 #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01 #define USB_ENDPOINT_TYPE_BULK 0x02 #define USB_ENDPOINT_TYPE_INTERRUPT 0x03 /通用子函数/ void Delayms(uint MS); /LED子函数/ void One_led(uchar number,uchar light); void All_led(uchar light); void Flow_LED(uchar MS); void Flash_LED(uchar number,uchar MS); /数码管子函数/ void One_smg_display(uchar data,uchar number); void All_smg_display(uchar *pdata); void Cycle_smg_display(uchar *pdata); /1602液晶管子函数/ void LCD1602_portini(void); uchar LCD1602_readbyte(uchar DatCmd); void LCD1602_sendbyte(uchar DatCmd, uchar dByte); void LCD1602_sendstr(uchar *ptString); void LCD1602_clear(void); uchar LCD1602_readBF(void); void LCD1602_gotoXY(uchar Row, uchar Col); void LCD1602_initial(void); /USB函数/ void D12_init(void); void OutB(uchar cmd,uchar dat); uchar InB(void); void Set_addren(uchar addr, uchar enable); void Set_EPen(uchar enable); void Set_mode(uchar config,uchar clkdiv); void Set_DMA(uchar bMode); uint Read_IntR(void); uchar Sel_EP(uchar endp); uchar Read_EPsta(uchar endp); uchar Read_LttransSta(uchar endp); void Set_EPsta(uchar endp,uchar stall); void Set_Sresume(void); uchar Read_EP(uchar endp,uchar len,uchar * buf); uchar Write_EP(uchar endp,uchar len,uchar * buf); void Ack_EP(uchar endp); void Clear_buf(uchar endp); void Stall_ep0(void); void S_trans(uchar * buf, uchar len); void Ep0_rxdone(void); void Ep0_txdone(void); void Ep1_txdone(void); void Ep1_rxdone(void); void Ep2_txdone(void); void Ep2_rxdone(void); void Reserved(void); void Get_status(void); void Clr_feature(void); void Set_feature(void); void Set_addr(void); void Get_descriptor(void); void Get_config(void); void Set_config(void); void Get_interface(void); void Set_interface(void); void USB_reconnect(void); void Control_handler(void); void Uart_sendB(uchar sendB);
注意以上是针对ATMEGA16单片机的,否则需要修改第一句#include
上一篇:嵌入式学习笔记16——AVR单片机之优势
下一篇:AVR单片机特性及开发编译环境
推荐阅读最新更新时间:2024-03-16 14:55