4.29

来源:互联网 发布:python 书籍 知乎 2016 编辑:程序博客网 时间:2024/05/21 09:26
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mmu.h"
#include "typedef.h"
#include "s3c2451_gpio.h"
#include "s3c2451_uart.h"
#include "s3c2451_irq.h"
#include "S3C2451_vector.h"
#include "S3C2451_Timer.h"
#include "S3C2451_rtc.h"
#include "S3C2451_lcd.h"


#define LED1 5
#define LED3  25
#define BIT(n) (1 << (n))


//extern const unsigned char gImage_test[];
extern const unsigned char char_mod8x16[][16];


const unsigned char china_mod8x16[][32] = {
    /*--  ??:  ?  --*/
/*--  ??12;  ??????????:?x?=16x16   --*/
0x00,0x00,0x3F,0xF8,0x21,0x08,0x21,0x08,0x2F,0xE8,0x21,0x08,0x21,0x08,0x3F,0xF8,
0x20,0x08,0x27,0xC8,0x24,0x48,0x24,0x48,0x27,0xC8,0x40,0x08,0x40,0x28,0x80,0x10,


/*--  ??:  ?  --*/
/*--  ??12;  ??????????:?x?=16x16   --*/
0x00,0x40,0x20,0x40,0x17,0xFC,0x10,0x40,0x83,0xF8,0x40,0x80,0x47,0xFE,0x10,0x90,
0x11,0x10,0x21,0xFE,0xE2,0x10,0x22,0x90,0x24,0x50,0x28,0x10,0x20,0x50,0x00,0x20,
};


void delay(unsigned int count)
{
int j = 1000;
int i = 0;
while(--j)
for(i =count; i > 0; i --);
}


//uart0 的中断服务程序
void uart0_irq(void)
{
U8 recv;

if(IRQ1_GetSUBPND(SUB_INT_RXD0) == BIT_SET){
IRQ1_ClearSUBPND(SUB_INT_RXD0);
recv = UART_ReceiveData(UART0);
   UART_SendData(UART0, recv);
}

if(IRQ1_GetSUBPND(SUB_INT_ERR0) == BIT_SET){
IRQ1_ClearSUBPND(SUB_INT_ERR0);
//打印出错
}

IRQ1_ClearPND(INT_UART0);


}
U32 count = 0;


int sendCurrentTimer(U32 time)
{
U32 tmpMSec =0,tmpSec = 0,tmpMin=0, tmpHour=0;
char Buffer[32];
memset(Buffer, 0, 32);

tmpMSec = time%1000;
tmpSec = time/1000;

tmpMin = tmpSec/60;
tmpSec = tmpSec%60;

tmpHour = tmpMin/60;
tmpMin = tmpMin%60;

sprintf(Buffer, "%02u:%02u:%02u::%03u\n", tmpHour, tmpMin, tmpSec, tmpMSec);
UART_SendString(UART0, (U8 *)Buffer);



// UART_Printf("%02u:%02u:%02u::%03u\n", tmpHour, tmpMin, tmpSec, tmpMSec);
return 0;
}


void eint0_irq(void)
{
IRQ1_ClearPND(INT_EINT0);
//UART_SendData(UART0, 'EInt0 Ocurr');
sendCurrentTimer(count*10);
}




void timer0_irq(void)
{
IRQ1_ClearPND(INT_TIMER0);
// UART_SendString(UART0, "timer0 interrupt.\n");
count ++;
if(count%100 == 0)
sendCurrentTimer(count*10);
}


void tick_irq(void)
{
char Buffer[32];

Time_InitTypeDef rtc_time;
IRQ1_ClearPND(INT_TICK);
RTC_Time_Get(&rtc_time);
UART_Printf("20%x-%02x-%02x %02x:%02x:%02x.\n", rtc_time.year, rtc_time.month, rtc_time.day, rtc_time.hour, rtc_time.minute, rtc_time.second);
 


  //时钟显示在屏幕上
// LCD_Clear(0);
// sprintf(Buffer,"20%x-%02x-%02x %02x:%02x:%02x.", rtc_time.year, rtc_time.month, rtc_time.day, rtc_time.hour, rtc_time.minute, rtc_time.second);
// LCDDisplay_String(100,100,0xfff,Buffer);
}


void Main()
{


GPIO_Init_Typedef gpio_init_struct;
UART_Init_Typedef uart_init_struct;
TIM_TimeBaseInitTypeDef tim_timbaseinit_structure;
Time_InitTypeDef rtc_time;

volatile int *extint0 = (volatile int *)0x56000088;

//MMU初始化:在程序最开始的时候调用
MMU_Init();

  count = 0;
//gpio
gpio_init_struct.pinx = GPIO_PIN_5 |  GPIO_PIN_6;
gpio_init_struct.mode = GPIO_MODE_OUT;
gpio_init_struct.udp = GPIO_UDP_DISABLE;
  GPIO_Init(GPIOB, gpio_init_struct);


gpio_init_struct.pinx = GPIO_PIN_0;
gpio_init_struct.mode = GPIO_MODE_ALT;
gpio_init_struct.udp = GPIO_UDP_DISABLE;
  GPIO_Init(GPIOF, gpio_init_struct);


//uart
uart_init_struct.baudrate = 115200;
uart_init_struct.mode = UART_Mode_TX | UART_Mode_RX; 
uart_init_struct.parity = Parity_No; //禁止奇偶校验
uart_init_struct.stop = STOP_1Bit;
uart_init_struct.wordwidth = WordWidth_8BIT;
UART_Init(UART0, uart_init_struct);

UART_IRQService_Init(UART0, (U32)uart0_irq); //注册中断服务程序

IRQ1_INTMask_Init(INT_UART0, ENABLE);
IRQ1_INTSUBMask_Init(SUB_INT_RXD0,ENABLE);
IRQ1_INTSUBMask_Init(SUB_INT_ERR0,ENABLE);

//外部中断
*extint0 |= (1<< 1);
*extint0 &= ~(1<<2);

pISR_EINT0 = (U32)eint0_irq;
IRQ1_INTMask_Init(INT_EINT0, ENABLE);

  UART_SendString(UART0, (U8 *)"Test Start !\n\r");

//timer pclk 66.5Mhz 1hz
tim_timbaseinit_structure.TIM_Prescale = 200;
tim_timbaseinit_structure.TIM_Scale = 0x02; //1/8
tim_timbaseinit_structure.TIM_CountVal = 41562;

TIM_TimeBaseInit(Timer_Ch0 , tim_timbaseinit_structure);

TIM_Interrupt_IRQInit(Timer_Ch0, (U32)timer0_irq);
IRQ1_INTMask_Init(INT_TIMER0,ENABLE);


//RTC
RTC_Time_Get(&rtc_time);
UART_Printf("20%x-%x-%x %x:%x:%x.\n", rtc_time.year, rtc_time.month, rtc_time.day, rtc_time.hour, rtc_time.minute, rtc_time.second);

rtc_time.year = 0x17;
rtc_time.month = 0x04;
rtc_time.day = 0x15;
rtc_time.hour = 0x17;
rtc_time.minute = 0x18;
rtc_time.second = 0;
RTC_Time_Set(rtc_time);

RTC_IRQ_Init( 127,ENABLE);
RTCTick_Interrupt_IRQInit((U32) tick_irq);
IRQ1_INTMask_Init(INT_TICK, ENABLE);


  //LCD
LCD_GPIO_Init();
LCD_Init();
LCD_Clear(0);  //清屏,屏幕变黑  (~0)透明

//LCD_Display_Bmp(0,0,165,220,gImage_test);   //显示图片

//LCD_Display_8x16(100,100,0xffffff,char_mod8x16[0]);   //显示字模(ASCII码)

 LCD_Display_8x16(100,100,0xffffff,china_mod8x16[0]);

//LCDDisplay_Char(1,1,0xfff,'b');    //显示字符

  //LCDDisplay_String(100,100,0xfff,"sdkhfkj");    //显示字符串

while(1){

// if(UART_IsRecved(UART0)){
// recv = UART_ReceiveData(UART0);
// UART_SendData(UART0, recv);
// }


 

 GPIO_WriteBit(GPIOB, GPIO_PIN_5, BIT_RESET);
 GPIO_WriteBit(GPIOB, GPIO_PIN_6, BIT_RESET);
delay(12000);

 GPIO_WriteBit(GPIOB, GPIO_PIN_5, BIT_SET);
 GPIO_WriteBit(GPIOB, GPIO_PIN_6, BIT_SET);
delay(12000);
};
}
0 0
原创粉丝点击