|
昨天我本打算写一篇关于arm的笔记的,可是昨天我学得是两款芯片的使用,重点是nor flash的使用,我翻翻它的资料,觉得只要对时序图有一定基础的人都能够搞定,自己也没什么语言可写,于是便没有记录,今天我学了两个东西,一个是串口的使用,一个是定时器的使用。总之这两个东西其实也不难,重点还是对lpc2200芯片相应模块的寄存器要熟悉,下面附上我写的程序,我把这两个综合在一块写的,注意要把开发板的UART0和PC的UART1(一般是上面那个)连接起来,同时还得把nitStacks.s中要把系统管理模式堆栈处的代码改为“MSR CPSR_c, #0x5f”,即使能IRQ,否则永远也实现不了。
#define spi_shcp 0x00000010 //0.4
#define spi_stcp 0x00000100 //0.8
#define spi_q7 0x00000020 //0.5
#define spi_ds 0x00000040 //0.6
#define UART_BPS 115200 //波特率
void delay(uint32 dly)
{ uint32 i;
for(; dly>0; dly--)
for(i=0; i<5000; i++);
}
void hc595send_data(uint8 data)
{
uint8 i;
IO0CLR = spi_stcp;
for(i=0;i<8;i++)
{
IO0CLR = spi_shcp;
if((data&0x80)!=0)IO0SET = spi_ds;
else IO0CLR = spi_ds;
data <<= 1;
IO0SET = spi_shcp;
}
IO0SET = spi_stcp;
}
const uint8 DISP_TAB[16] = { 0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,
0x81,0x42,0x24,0x18,0x24,0x42,0x81,0x00 };
void UART0_Init(void)
{
uint16 fdiv;
U0LCR = 0x83; //DLAB = 1,可设置波特率
fdiv = (Fpclk/16)/UART_BPS; //设置波特率
U0DLM = fdiv/256;
U0DLL = fdiv%256;
U0LCR = 0x03; //DLAB = 0
}
void UART_SendByte(uint8 data)
{
U0THR = data;
while((U0LSR&0x40)==0);
}
void URAT_Send(uint8 *str)
{
while(1)
{
if(*str == '\0')break;
UART_SendByte(*str++);
}
}
uint8 mat=0;
void __irq IRQ_Timer0(void)
{
//uint8 i=0;
hc595send_data(~DISP_TAB[mat]);
UART_SendByte(mat);
if(++mat == 16)mat = 0;
T0IR = 0x01;
VICVectAddr = 0x00;
}
void Timer0_Init(void)
{
T0TC = 0;//定时器设置为0,即从0开始计数
T0PR = 0;//时钟不分频
T0MCR = 0x03;//设置TIMER0匹配后复位T0TC,并产生中断标志
T0MR0 = Fpclk;//设置10s匹配值
T0TCR = 0x01;//启动定时器
VICIntSelect = 0x00;
VICVectCntl0 = 0x24;
VICVectAddr0 = (uint32)IRQ_Timer0;
VICIntEnable = 0x00000010;
}
int main (void)
{// add user source code
uint8 i=0;
PINSEL0 = 0x00000005;
IO0DIR = 0x00000150;//0001 1/0 101 0000
UART0_Init();
Timer0_Init();
while(1);
/*如果不使用中断调用程序,也是可以的,那要把imer0_Init()函数下的关于中断的语句屏蔽掉,同时把下面的while语句开启,还有把上面的while屏蔽;也一样可以达到同样的效果
while(1)
{
while((T0IR&0x01)==0);
T0IR = 0x01;
hc595send_data(~DISP_TAB[ i]);
URAT_Send((uint8 *)DISP_TAB);
if(++i == 16)i = 0;
}
*/
return 0;
} |
|