📄 blinky1.c
字号:
#include "LPC2294.H"
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <setjmp.h>
#include <rt_misc.h>
typedef unsigned char uint8;
typedef signed char int8;
typedef unsigned short uint16;
typedef signed short int16;
typedef unsigned int uint32;
typedef signed int int32;
typedef float fp32;
typedef double fp64;
typedef unsigned char INT8U;
typedef signed char INT8;
typedef unsigned short INT16U;
typedef signed short INT16;
typedef unsigned int INT32U;
typedef signed int INT32;
typedef float FP32;
typedef double FP64;
#define Fosc 11059200 //Crystal frequence,10MHz~25MHz,should be the same as actual status.
//应当与实际一至晶振频率,10MHz~25MHz,应当与实际一至
#define Fcclk (Fosc * 4) //System frequence,should be (1~32)multiples of Fosc,and should be equal or less than 60MHz.
//系统频率,必须为Fosc的整数倍(1~32),且<=60MHZ
#define Fcco (Fcclk * 4) //CCO frequence,should be 2、4、8、16 multiples of Fcclk, ranged from 156MHz to 320MHz.
//CCO频率,必须为Fcclk的2、4、8、16倍,范围为156MHz~320MHz
#define Fpclk (Fcclk / 4) * 1 //VPB clock frequence , must be 1、2、4 multiples of (Fcclk / 4).
//VPB时钟频率,只能为(Fcclk / 4)的1、2、4倍
void lcd_putchar(unsigned char character);
void lcd_putsf(unsigned char *string , unsigned char n) ;
void lcd_gotoxy(unsigned char x,unsigned char y) ;
//P0.12
#define LCD_RST (0x01 << 12)
#define LCD_RST_GPIO() PINSEL0 &= ~(0x03 << 24)
#define LCD_RST_OUT() IO0DIR |= LCD_RST
#define LCD_RST_SET() IO0SET |= LCD_RST
#define LCD_RST_CLR() IO0CLR |= LCD_RST
//p0.11
#define LCD_CS (0x01 << 11)
#define LCD_CS_GPIO() PINSEL0 &= ~(0x03 << 22)
#define LCD_CS_OUT() IO0DIR |= LCD_CS
#define LCD_CS_SET() IO0SET |= LCD_CS
#define LCD_CS_CLR() IO0CLR |= LCD_CS
//P1.23
#define LCD_DC (0x01 << 23)
#define LCD_DC_GPIO() PINSEL2 &= ~(0x02 <<2)
#define LCD_DC_OUT() IO1DIR |= LCD_DC
#define LCD_DC_SET() IO1SET |= LCD_DC
#define LCD_DC_CLR() IO1CLR |= LCD_DC
//LED0 P0.31
#define LED0 (0x01 << 31)
#define LED0_GPIO() PINSEL1 &= ~(3 <<30)
#define LED0_OUT() IO0DIR |= LED0
#define LED0_SET() IO0SET |= LED0
#define LED0_CLR() IO0CLR |= LED0
//LED1 P0.8
#define LED1 (0x01 << 8)
#define LED1_GPIO() PINSEL0 &= ~(0x03 <<16)
#define LED1_OUT() IO0DIR |= LED1
#define LED1_SET() IO0SET |= LED1
#define LED1_CLR() IO0CLR |= LED1
//LED2 p0.9
#define LED2 (0x01 << 9)
#define LED2_GPIO() PINSEL0 &= ~(0x03 <<18)
#define LED2_OUT() IO0DIR |= LED2
#define LED2_SET() IO0SET |= LED2
#define LED2_CLR() IO0CLR |= LED2
//LED3 P0.10
#define LED3 (0x01 << 10)
#define LED3_GPIO() PINSEL0 &= ~(0x03 <<20)
#define LED3_OUT() IO0DIR |= LED3
#define LED3_SET() IO0SET |= LED3
#define LED3_CLR() IO0CLR |= LED3
//LED4 P0.13
#define LED4 (0x01 << 13)
#define LED4_GPIO() PINSEL0 &= ~(0x03 <<26)
#define LED4_OUT() IO0DIR |= LED4
#define LED4_SET() IO0SET |= LED4
#define LED4_CLR() IO0CLR |= LED4
//LED5 P1.22
#define LED5 (0x01 << 22)
#define LED5_GPIO() PINSEL2 &= ~(0x02 <<2)
#define LED5_OUT() IO1DIR |= LED5
#define LED5_SET() IO1SET |= LED5
#define LED5_CLR() IO1CLR |= LED5
//LED6 P0.14
#define LED6 (0x01 << 14)
#define LED6_GPIO() PINSEL0 &= ~(0x03 <<28)
#define LED6_OUT() IO0DIR |= LED6
#define LED6_SET() IO0SET |= LED6
#define LED6_CLR() IO0CLR |= LED6
//LED7 P1.21
#define LED7 (0x01 << 21)
#define LED7_GPIO() PINSEL2 &= ~(0x02 <<2)
#define LED7_OUT() IO1DIR |= LED7
#define LED7_SET() IO1SET |= LED7
#define LED7_CLR() IO1CLR |= LED7
//p0.25
#define KEY_PLAY (0x01 << 25)
#define KEY_PLAY_GPIO() PINSEL1 &= ~(0x03 <<18)
#define KEY_PLAY_IN() IO0DIR &=~KEY_PLAY
#define KEY_PLAY_STATE() (IO0PIN & KEY_PLAY)
//P0.26
#define KEY_UP (0x01 << 26)
#define KEY_UP_GPIO() PINSEL1 &= ~(0x03 <<20)
#define KEY_UP_IN() IO0DIR &=~KEY_UP
#define KEY_UP_STATE() (IO0PIN & KEY_UP)
//P0.27
#define KEY_DOWN (0x01 << 27)
#define KEY_DOWN_GPIO() PINSEL1 &= ~(0x03 <<22)
#define KEY_DOWN_IN() IO0DIR &=~KEY_DOWN
#define KEY_DOWN_STATE() (IO0PIN & KEY_DOWN)
//P0.28
#define KEY_VOLD (0x01 << 28)
#define KEY_VOLD_GPIO() PINSEL1 &= ~(0x03 <<24)
#define KEY_VOLD_IN() IO0DIR &=~KEY_VOLD
#define KEY_VOLD_STATE() (IO0PIN & KEY_VOLD)
//P0.29
#define KEY_VOLU (0x01 << 29)
#define KEY_VOLU_GPIO() PINSEL1 &= ~(0x03 <<26)
#define KEY_VOLU_IN() IO0DIR &=~KEY_VOLU
#define KEY_VOLU_STATE() (IO0PIN & KEY_VOLU)
//P0.30
#define KEY_MODE (0x01 << 30)
#define KEY_MODE_GPIO() PINSEL1 &= ~(0x03 <<28)
#define KEY_MODE_IN() IO0DIR &=~KEY_MODE
#define KEY_MODE_STATE() (IO0PIN & KEY_MODE)
INT8U FLGG=0;
void __irq Timer0_Exception(void)
{
if(FLGG==0 ) { IO0SET=LED4; FLGG=1;}
else {IO0CLR=LED4; FLGG=0; }
T0IR = 0x01;
VICVectAddr = 0;
}
void Time0Init(void)
{
T0PR=99;
T0MCR = 0x03;
T0MR0 = 110592;
T0TCR = 0x03;
T0TCR = 0x01;
//VICIntEnClr = 0xffffffff;
VICIntSelect = 0x00;
VICVectCntl0 = (0x20 | 0x04);
VICVectAddr0 = (uint32) Timer0_Exception;
VICIntEnable =( 0x0ff <<1); //04
}
void InitialiseUART0(uint32 bps)
{
uint16 Fdiv;
PINSEL0 = (PINSEL0 & 0xfffffff0) | 0x05; /* Select the pins for Uart 选择管脚为UART0 */
U0LCR = 0x80; /* Enable to access the frequenc regecter
允许访问分频因子寄存器 */
Fdiv = (Fpclk / 16) / bps; /* Set the baudrate设置波特率 */
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0x03; /* Disable to access the frequenc regecter
禁止访问分频因子寄存器 */
/* set to 8,1,n 且设置为8,1,n */
U0IER = 0x00; /* Disable interrupt禁止中断 */
U0FCR = 0x00; /* initial FIFO 初始化FIFO */
}
//p0.15
#define VS1003_POWER (0x01 << 15)
#define VS1003_POWER_GPIO() PINSEL0 &= ~(1<<30)
#define VS1003_POWER_OUT() IO0DIR |= VS1003_POWER
#define VS1003_POWER_SET() IO0SET |= VS1003_POWER
#define VS1003_POWER_CLR() IO0CLR |= VS1003_POWER
//p0.07
#define SPI0_CS (0x01 << 7)
#define SPI0_CS_GPIO() PINSEL0 &= ~(0x03 << 14)
#define SPI0_CS_OUT() IO0DIR |= SPI0_CS;
#define SPI0_CS_SET() IO0SET |= SPI0_CS;
#define SPI0_CS_CLR() IO0CLR |= SPI0_CS;
//p0.06
#define SPI0_MOSI (0x01 << 6)
#define SPI0_MOSI_GPIO() PINSEL0 &= ~(0x03 << 12)
#define SPI0_MOSI_OUT() IO0DIR |= SPI0_MOSI
#define SPI0_MOSI_CLR() IO0CLR = SPI0_MOSI
//p0.05
#define SPI0_MISO (0x01 << 5)
#define SPI0_MISO_GPIO() PINSEL0 &= ~(0x03 << 10)
#define SPI0_MISO_OUT() IO0DIR |= SPI0_MISO
#define SPI0_MISO_CLR() IO0CLR = SPI0_MISO
//p0.04
#define SPI0_SCK (0x01 << 4)
#define SPI0_SCK_GPIO() PINSEL0 &= ~(0x03 << 8)
#define SPI0_SCK_OUT() IO0DIR |= SPI0_SCK
#define SPI0_SCK_CLR() IO0CLR = SPI0_SCK
//P1.24
#define VS1003_XDCS (0x01 << 24)
#define VS1003_XDCS_GPIO() PINSEL2 &= ~(0x02 <<4)
#define VS1003_XDCS_OUT() IO1DIR |= VS1003_XDCS
#define VS1003_XDCS_SET() IO1SET |= VS1003_XDCS
#define VS1003_XDCS_CLR() IO1CLR |= VS1003_XDCS
//p0.03
#define VS1003_XRESET (0x01 << 3)
#define VS1003_XRESET_GPIO() PINSEL0 &= ~(0x03 << 6)
#define VS1003_XRESET_OUT() IO0DIR |= VS1003_XRESET
#define VS1003_XRESET_SET() IO0SET = VS1003_XRESET
#define VS1003_XRESET_CLR() IO0CLR = VS1003_XRESET
//p1.25
#define VS1003_DREQ (0x01 << 25)
#define VS1003_DREQ_GPIO() PINSEL2 &= ~(0x02 <<4)
#define VS1003_DREQ_IN() IO1DIR &= ~VS1003_DREQ
#define VS1003_DREQ_STATE() (IO1PIN & VS1003_DREQ)
//vs1003
#define VS1003_WRITE_COM 0x02
#define VS1003_READ_COM 0x03
#define VS1003_SPI_MODE 0x00
#define VS1003_SPI_STATUS 0x01
#define VS1003_SPI_BASS 0x02
#define VS1003_SPI_CLOCKF 0x03
#define VS1003_SPI_DECODE_TIME 0x04
#define VS1003_SPI_AUDATA 0x05
#define VS1003_SPI_WRAM 0x06
#define VS1003_SPI_WRAMADDR 0x07
#define VS1003_SPI_HDAT0 0x08
#define VS1003_SPI_HDAT1 0x09
#define VS1003_SPI_AIADDR 0x0A
#define VS1003_SPI_VOL 0x0B
#define VS1003_SPI_AICTRL0 0x0C
#define VS1003_SPI_AICTRL1 0x0D
#define VS1003_SPI_AICTRL2 0x0E
#define VS1003_SPI_AICTRL3 0x0F
#define VS1003_SM_DIFF 0x01
#define VS1003_SM_JUMP 0x02
#define VS1003_SM_RESET 0x04
#define VS1003_SM_OUTOFWAV 0x08
#define VS1003_SM_PDOWN 0x10
#define VS1003_SM_TESTS 0x20
#define VS1003_SM_STREAM 0x40
#define VS1003_SM_PLUSV 0x80
#define VS1003_SM_DACT 0x100
#define VS1003_SM_SDIORD 0x200
#define VS1003_SM_SDISHARE 0x400
#define VS1003_SM_SDINEW 0x800
#define VS1003_SM_ADPCM 0x1000
#define VS1003_SM_ADPCM_HP 0x2000
#define CMD_SD_INIT 0x00 /* SD卡初始化卡命令 */
#define CMD_SD_READ 0x01 /* SD卡读命令 */
#define CMD_SD_WRITE 0x02 /* SD卡写命令 */
#define CMD_SD_ERASE 0x03 /* SD卡擦除命令 */
#define CMD_DATA_TRANS 0x04 /* 将sd_buf中的数据发送到PC机 */
#define CMD_DATA_RECV 0x05 /* 接收来自串口的数据,并放入sd_buf中 */
#define TRUE 1
#define FALSE 0
#define ON 1
#define OFF 0
#define MSK_IDLE 0x01
#define MSK_ERASE_RST 0x02
#define MSK_ILL_CMD 0x04
#define MSK_CRC_ERR 0x08
#define MSK_ERASE_SEQ_ERR 0x10
#define MSK_ADDR_ERR 0x20
#define MSK_PARAM_ERR 0x40
#define MSK_TOK_ERROR 0x01
#define MSK_TOK_CC_ERROR 0x02
#define MSK_TOK_ECC_FAILED 0x04
#define MSK_TOK_CC_OUTOFRANGE 0x08
#define MSK_TOK_CC_LOCKED 0x10
#define SD_TOK_READ_STARTBLOCK 0xFE
#define SD_TOK_WRITE_STARTBLOCK 0xFE
#define SD_TOK_READ_STARTBLOCK_M 0xFE
#define SD_TOK_WRITE_STARTBLOCK_M 0xFC
#define SD_TOK_STOP_MULTI 0xFD
#define SD_RESP_DATA_MSK 0x0F //数据响应掩码
#define SD_RESP_DATA_ACCETPTED 0x05 //数据被接受
#define SD_RESP_DATA_REJECT_CRC 0x0B //由于CRC错误而被拒绝
#define SD_RESP_DATA_REJECT_WRITE 0x0D //由于写错误而被拒绝
#define SD_WAIT_READ 0x00 //读等待
#define SD_WAIT_WRITE 0x01 //写等待
#define SD_WAIT_ERASE 0x02 //擦除等待
#define SD_READREG_TIMEOUT 8
/******************************** 基本命令集 Basic command set **************************/
/* 复位SD 卡 Reset cards to idle state */
#define CMD0 0
#define CMD0_R 1
/* 读OCR寄存器 Read the OCR (MMC mode, do not use for SD cards) */
#define CMD1 1
#define CMD1_R 1
/* 读CSD寄存器 Card sends the CSD */
#define CMD9 9
#define CMD9_R 1
/* 读CID寄存器 Card sends CID */
#define CMD10 10
#define CMD10_R 1
/* 停止读多块时的数据传输 Stop a multiple block (stream) read/write operation */
#define CMD12 12
#define CMD12_R 2
/* 读 Card_Status 寄存器 Get the addressed card's status register */
#define CMD13 13
#define CMD13_R 3
/***************************** 块读命令集 Block read commands **************************/
/* 设置块的长度 Set the block length */
#define CMD16 16
#define CMD16_R 1
/* 读单块 Read a single block */
#define CMD17 17
#define CMD17_R 1
/* 读多块,直至主机发送CMD12为止 Read multiple blocks until a CMD12 */
#define CMD18 18
#define CMD18_R 1
/***************************** 块写命令集 Block write commands *************************/
/* 写单块 Write a block of the size selected with CMD16 */
#define CMD24 24
#define CMD24_R 1
/* 写多块 Multiple block write until a CMD12 */
#define CMD25 25
#define CMD25_R 1
/* 写CSD寄存器 Program the programmable bits of the CSD */
#define CMD27 27
#define CMD27_R 1
/***************************** 写保护 Write protection *****************************/
/* Set the write protection bit of the addressed group */
#define CMD28 28
#define CMD28_R 2
/* Clear the write protection bit of the addressed group */
#define CMD29 29
#define CMD29_R 2
/* Ask the card for the status of the write protection bits */
#define CMD30 30
#define CMD30_R 1
/***************************** 擦除命令 Erase commands *******************************/
/* 设置擦除块的起始地址 Set the address of the first write block to be erased */
#define CMD32 32
#define CMD32_R 1
/* 设置擦除块的终止地址 Set the address of the last write block to be erased */
#define CMD33 33
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -