嵌入式读书器,c编写

类别:编程语言 点击:0 评论:0 推荐:

/****************************************************************************
** File Name: main.c
** Description:
** Generated Automatically for: ARM7TDMI-S3c44b0x Evaluation Board.
** Time: Friday, August 13, 2004 11:42:11
** Copyright :wangyinfei
****************************************************************************/
#include <string.h>
#include "..\inc\44b.h"
#include "..\inc\44blib.h"
#include "..\inc\def.h"
#include "..\inc\option.h"
#include  "www.h"
void Isr_Init(void)
{
    U32 i;
   
    //pISR_UNDEF=(unsigned)HaltUndef;
   // pISR_SWI  =(unsigned)HaltSwi;
   // pISR_PABORT=(unsigned)HaltPabort;
   //pISR_DABORT=(unsigned)HaltDabort;
   
     for(i=_RAM_STARTADDRESS;i<(_RAM_STARTADDRESS+0x20);i+=4)
     {
  *((volatile unsigned *)i)=0xEA000000+0x1FFE;
     }
    rINTCON=0x5;   // Non-vectored,IRQ enable,FIQ disable   
    rINTMOD=0x0;   // All=IRQ mode
    rINTMSK|=BIT_GLOBAL|BIT_EINT0;   // All interrupt is masked.
}

int __main()
{
    Isr_Init();
    Port_Init();
    Lcd_Init();
    Lcd_Active_Clr();
    Test_Kb( );
  
    digit_led_Symbol(8);
 Lcd_Active_Clr();
  
    digit_led_Symbol(5);
    disp16(bb,5,0);
    digit_led_Symbol(4);
while(1)
{
digit_led_Symbol(3);
Test_Kb( );
digit_led_Symbol(2);
//keyboardint();
//init_keyboard();
}

}

/********************************
lcd.c文件
copyright:wangyinfei
**********************************/
#include "..\inc\44b.h"
#include "..\inc\44blib.h"
#include "..\inc\ASII.H"
#include "..\inc\hanzi.h"

#define INT32U unsigned int
#define INT16U unsigned short
#define S32 int
#define S16 short int
#define INT8U unsigned char
#define U16 unsigned short int
#define INT16  short

int p=0;
int pp=0;
char * page[100];
/*******************************************
沿时程序
********************************************/
 void  delay(long n)
 {
   long i;
   long k;
   long j;
   for(i=0;i<n;i++)
   {
    for(k=0;k<60;k++)
    {
      for(j=0;j<1000;j++)
      {
        int n=1;
        int m=2;
      }
    }
   }
 }

/*****************************************
交换usY0,usY1
*****************************************/   

void GUISWAP(INT16 * usY1,INT16 * usY0)
{ short M;
  M=* usY1;
  *usY1=*usY0;
  *usY0=M;
  return 0;
}
/*****************************************
*Embest arm教学系统软件宏定义
*****************************************/
#define M5D(n)  ((n)&0x1fffff)   //高3位清0宏
#define BLACK   0XFFFFFFFF
#define WHITE   0X0

/*****************************************
*S3C44B0X的lcd控制寄存器访问地址
*******************************************/
/*#define rLCDCON1       (*(voatile unsigned *)0x1f00000)
#define rLCDCON2       (*(voatile unsigned *)0x1f00004)
#define rLCDCON3       (*(voatile unsigned *)0x1f00040)
#define rLCDSADDR1       (*(voatile unsigned *)0x1f00008)
#define rLCDSADDR2       (*(voatile unsigned *)0x1f0000c)
#define rLCDSADDR3       (*(voatile unsigned *)0x1f00010)
#define rREDLUT       (*(voatile unsigned *)0x1f00014)
#define rGREENLUT       (*(voatile unsigned *)0x1f00018)
#define rBLUELUT       (*(voatile unsigned *)0x1f0001c)
#define rDP1_2       (*(voatile unsigned *)0x1f00020)
#define rDP4_7       (*(voatile unsigned *)0x1f00024)
#define rDP3_5       (*(voatile unsigned *)0x1f00028)
#define rDP2_3       (*(voatile unsigned *)0x1f0002c)
#define rDP5_7       (*(voatile unsigned *)0x1f00030)
#define rDP3_4       (*(voatile unsigned *)0x1f00034)
#define rDP4_5       (*(voatile unsigned *)0x1f00038)
#define rDP6_7       (*(voatile unsigned *)0x1f0003c)
#define rDITHMODE       (*(voatile unsigned *)0x1f00044)*/
/********************************************
s3cev40实验系统的lcd属性定义
********************************************/
#define MLCD_320_240     (3)
#define LCD_TYPE         MLCD_320_240
#define SCR_XSIZE        (160)
#define SCR_YSIZE        (240)
#define LCD_XSIZE        (160)
#define LCD_YSIZE        (240)
/*********************************************
*s3c44b0x的lcd控制器宏定义
************************************************/
#define MIDE_GREY16  (16)
#define CLKVAL_GREY16  (13)

#define HOZVAL  (LCD_XSIZE/4-1)
#define LINEVAL  (LCD_YSIZE-1)
#define MVAL    (13)
#define MVAL_USED   0
/**********************************************
*embest arm教学系统的lcd显示缓冲区
***********************************************/
#define ARRAY_SIZE_GREY16    (SCR_XSIZE/2*SCR_YSIZE)

#define LCD_BUF_SIZE        (SCR_XSIZE*SCR_YSIZE/2)
#define LCD_ACTIVE_BUFFER   (0xc400000)
#define LCD_VIRTUAL_BUFFER  (0xc400000+LCD_BUF_SIZE)

/************************************************
*函数名:Lcd_Init()
*功能:  初始化lcd控制器
*参数:   无
*返回:   无
**************************************************/
void Lcd_Init(void)
{
rDITHMODE=  0X1223a;
rDP1_2  =  0x5a5a;
rDP4_7  =  0x366cd9b;
rDP3_5  =  0xda5a7;
rDP2_3  =  0xad7;
rDP5_7  =  0xfeda5b7;
rDP3_4  =  0xebd7;
rDP4_5  =  0xebfd7;
rDP6_7  =  0x7efdfbf;

/*---------------LCDCON1控制字清0----------------*/
rLCDCON1=(0)|(1<<5)|(MVAL_USED<<7)|(0X3<<8)|(0X3<<10)|(CLKVAL_GREY16<<12);
/*---------------LCDCON2控制字设置lcd分辨率320*240,水平线扫描空闲时间10mclk----------------*/
rLCDCON2=(LINEVAL)|(HOZVAL<<10)|(10<<21);
/*---------------LCDSADDR1-3为帧缓冲区起始地址----------------*/
rLCDSADDR1=(0X0<<27)|(((LCD_ACTIVE_BUFFER>>22)<<21)|M5D(LCD_ACTIVE_BUFFER>>1));
/*---------------设置:16级灰度,LCDBANK,LCDBDEU----------------*/
rLCDSADDR2=M5D(((LCD_ACTIVE_BUFFER+(SCR_XSIZE*LCD_YSIZE/2/4))>>1))|(MVAL<<21);
rLCDSADDR3=(LCD_XSIZE/4/4)|(((SCR_XSIZE-LCD_XSIZE)/4/4)<<9);
//重新设置lcdcon1:4位单扫描模式;WDLY=8CLK,WLH=8CLK
rLCDCON1=(1)|(1<<5)|(MVAL_USED<<7)|(0X3<<8)|(0X3<<10)|(CLKVAL_GREY16<<12);
rBLUELUT=0xfa40;
/*---------------LCD驱动逻辑使能,打开背光----------------*/
rPDATE=rPDATE&0X0e;
}
/*******************************************
描点函数,lcd像素显示
LcdPutPixel(x,y,c)-----发送到显示缓冲区(直接驱动lcd)
********************************************/
 LcdPutPixel(INT16 x,INT16 y,INT8U c)
  { INT32U * buffer=(INT32U *)LCD_ACTIVE_BUFFER;
  *(buffer+y*SCR_XSIZE/32+x/32)|=(0x80000000>>(x%32));
  }
/**************************************************
//函数名   Lcd_Active_Clr()
//功能    清屏
//参数   无
//返回   无
**********************************************/
void Lcd_Active_Clr(void)
{
 INT32U  i;
 INT32U  * pDisp=(INT32U *)LCD_ACTIVE_BUFFER;
  for(i=0;i<(SCR_XSIZE*SCR_YSIZE/8);i++)
 {
   *pDisp++=WHITE;
  
 }
 return;
}
/***************************************************
显示指定缓冲区数据的函数
****************************************************/
void displaylcd(unsigned char *Buf)
{
    unsigned int *pbuffer,temp_data;
     int i;
    
    pbuffer =(INT16U *)LCD_ACTIVE_BUFFER;
    for(i = 0; i< (4800/4) ;i++)
    {
       temp_data = (Buf[i*4] << 24) + (Buf[i*4+1] << 16) + (Buf[i*4+2] << 8) +(Buf[i*4+3]);
        pbuffer[i] = ~temp_data;
 Delay(3);
    }
}
/***************************************
//函数名   Lcd_Draw_HLine()
//功能    用指定颜色画水平线
//参数    usX0,usY0   起始坐标
//          usX1      结束X坐标
//          ucColor   线条颜色
//          usWidth   线条宽度
//返回   无
/*******************************************
英文显示16x16
******************************************/
 void dischar16(char hao,unsigned char line,unsigned char xdot)
{  
     unsigned char *pbuffer;
     unsigned int i;
     if(xdot%2==0)xdot+=1;
     else xdot-=1;
     //delay(1);

     pbuffer =(unsigned char *) LCD_ACTIVE_BUFFER; 
   
   for (i=0;i<16;i++)
   {
     pbuffer[20*i+16*20*line+xdot*2]=hzdot[2*i+1+32*hao];
     pbuffer[20*i+16*20*line+xdot*2+1]=hzdot[2*i+32*hao];
     }
}
/*******************************************
英文字符串显示16x16
******************************************/
 void disstr16( char * hao,unsigned char line,unsigned char xdot)
 {  
     char * m=hao;
     while(* m!=0)
     {  if(*m=='\n'){line++;xdot=0;m++;}
        if(xdot>=10){xdot-=10;line++;}
        if(line>=15){line-=15;delay(3);Lcd_Active_Clr();}
        dischar16(* m,line,xdot);
        m++;
        xdot++;
       
     }
 }
 /*******************************************
中文字符串显示16x16
******************************************/
 void disp16( char * hao,unsigned char line,unsigned char xdot)
 {    unsigned char * pbuffer;
     unsigned int i,x,y;
     unsigned char xx;
    
    // delay(1);

     pbuffer =(unsigned char *) LCD_ACTIVE_BUFFER; 
    
    
     char * m=hao;
     page[p]=m;
     while(* m!=0)
     { 
        if(*m=='\n'){line++;xdot=0;m++;}
         if(xdot>=10){xdot-=10;line++;delay(1);}
        if(line>=15){line-=15;page[(p+1)%100]=m;delay(1);
                    while(1){Test_Kb( );}
                    Lcd_Active_Clr();
                    }
       
        if(*m<=0x20){m++;xdot++;continue;}
        if(*m<=0xa0){dischar16(* m,line,xdot);m++;xdot++;continue;}
        x=* (m);
        y=* (m+1);
      
        xx=xdot;
        if(xdot%2==0)xx+=1;
         else xx-=1;
       for (i=0;i<16;i++)
      {
         pbuffer[20*i+16*20*line+xx*2]=hanzidot[2*i+1+((x-1-0xa0)*94+(y-0xa0-1))*32];
         pbuffer[20*i+16*20*line+xx*2+1]=hanzidot[2*i+((x-1-0xa0)*94+(y-0xa0-1))*32];
       } 
        m+=2;
        xdot++;
       
     }
 }

 

 


 

本文地址:http://com.8s8s.com/it/it27017.htm