⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd.c.bak

📁 port of ARM to NOkia 3310 display
💻 BAK
📖 第 1 页 / 共 2 页
字号:
#include "globals.h"
#include "EcosLogo.c"


/* Beep Routines
   Buzzer PORTX, bitY 
   10,5  //1kHz per secund
   5,5   //2kHz 
   7,5   //1428 Hz for .56 sec
   6,5
   Anton Ivanov '02
*/


void beep(unsigned char Rate, unsigned char Num)
{
	unsigned char count,count1;
	
	while(Num--)
	{
		for (count1 = 0;count1 < 20; ++count1)   
		{
			beep_0;
			for (count=0;count < 10;count++)
			{
			       hal_delay_us(Rate);  
			}
			beep_1;
			for (count=0;count < 10;count++)
			{
				hal_delay_us(Rate);  
			}
		}
	}
	
	return;
}


/*
        music
*/
void music(void)
{
    unsigned char c;
    
    for(c=5;c!=15;++c)
    {
        beep(c,3);
    }
    hal_delay_us(10);  
    for(c=15; c!=5; --c)
    {
        beep(c,3);
    }
    return;
}


void LedButInit(void)
{
     (*(volatile unsigned long *)ASHLING_IODIR) |= 0x01<< LEDPIN ;    // define LED-Pin as output
     (*(volatile unsigned long *)ASHLING_IODIR) &=~(0x01<< SWPIN  );	// define Switch-Pin as input
     (*(volatile unsigned long *)ASHLING_IODIR) |= 0x01<< SOUNDPIN ;    // define SOUND-Pin as output
    return;
}


///////////////////////////////////////////////////// B/W LCD /////////////////////////////////////////////////////////////////////////////////////


/*
	NOKIA INIT SUB
*/
void nokia_init(unsigned char contrast)
{
       //init port
      (*(volatile unsigned long *)ASHLING_IODIR) |= 0x1F<< 26  ;        
        
               
	// nokia LCD init
	nok_dc_1;                                       // bytes are stored in the display data ram, address counter, incremented automatically
       nok_cs_1;                                       // chip disabled
                         
        nok_res_0;                                      // reset chip during 50ms
         hal_delay_us(20000);  
        nok_res_1;
        
	bytefornokia=0x21;			// set extins extended instruction set
	nokia_write_command();
         hal_delay_us(20000);  
        bytefornokia = contrast;		// Vop  {184d - 190d}
	nokia_write_command();
	 hal_delay_us(20000);  
	bytefornokia = 0x06;			// Temp Coeficient
	nokia_write_command();
         hal_delay_us(20000);  
   	bytefornokia=0x13;			// bias 
	nokia_write_command();
         hal_delay_us(20000);  
	bytefornokia=0x20;			// 0x20 horizontal mode from left to right, X axe are incremented automatically , 0x22 for vertical addressing ,back on normal instruction set too
	nokia_write_command();
         hal_delay_us(20000);  
	bytefornokia=0x09;			// all on
	nokia_write_command();
	 hal_delay_us(20000);  	
        nokia_build_DDRAM();			// reset DDRAM, otherwise the lcd is blurred with random pixels
         hal_delay_us(20000);  
	bytefornokia=0x08;			// mod control blank change (all off)
	nokia_write_command();
	 hal_delay_us(20000);  			
	bytefornokia=0x0c;			// mod control normal change 
	nokia_write_command();
	 hal_delay_us(20000);  
      
      	return;
}


void LcdContrast (unsigned char contrast)
{
	//  LCD Extended Commands.
	bytefornokia = 0x21;			// mod control normal change 
	nokia_write_command();
    
   	bytefornokia = 0x80 | contrast;			
	nokia_write_command();

    

    //  LCD Standard Commands, horizontal addressing mode.
	bytefornokia = 0x20;			
	nokia_write_command();

   	return;
}



/*
	NOKIA WRITE CMD SUB
*/
void nokia_write_command(void)
{
        nok_dc_0;	// byte is a command it is read with the eight SCLK pulse
	nok_cs_0;	// chip enabled 
	nokia_write_dorc();
	nok_cs_1;	// chip disabled
}



/*
	NOKIA WRITE DATA SUB
*/
void nokia_write_data(void)
{
	nok_dc_1;
	nok_cs_0;	// chip enabled
	nokia_write_dorc();
	nok_cs_1;	// chip disabled
}



/*	
	NOKIA WRITE DORC SUB
*/
void nokia_write_dorc(void)			// serial write data or command subroutine
{
	unsigned char c;
	
	for (c=8;c>0;c--) 
        {
		nok_sclk_0;
		if ((bytefornokia&0x80)==0)
		{
			nok_sda_0;
		}
		else 
		{
			nok_sda_1;
		}
		nok_sclk_1;
		bytefornokia = bytefornokia<<1;
	}
}



/*
	NOKIA BUILD DDRAM SUB
*/
void nokia_build_DDRAM(void)	// clear all DDRAM (set all bits to zero)
{
	signed char ch, cm, cl;
	
	nok_sda_0;
	nok_dc_1;
	nok_cs_0;
	for (ch=6;ch>0;ch--)
        {				// 6 rows
		for (cm=84;cm>0;cm--)
                {			// 84 columns
			for (cl=8;cl>0;cl--)
                        {		// 8 pixels
				nok_sclk_0;
				nok_sclk_1;
			}
		}
        }
		nok_cs_1;
}




/*
	NOKIA GOTO XY SUB
*/
void nokia_gotoxy (unsigned char  xnokia, unsigned char  ynokia)	// Nokia LCD Position cursor
{
		bytefornokia=(0x40|(ynokia&0x07));		// Y axe initialisation: 0100 0yyy	
		nokia_write_command();
		
		bytefornokia=(0x80|(xnokia&0x7f));		// X axe initialisation: 1xxx xxxx
		nokia_write_command();
		
		return;
}



/*
	PRINT MESSAGE SUB
*/
void nokia_printmessage(const char* message, unsigned char big)	// Write message to LCD (C string type)
{
	while (*message)							// Look for end of string
		ascii_to_nokia(*message++, big);			//	
		
	return;
}



/*
	PRINT CHARACTER SUB
*/
void nokia_printchar(unsigned char  c, unsigned char big )					// Write 1 character to LCD 
{
	ascii_to_nokia(FontLookup[c][0], big);
}






/*
	ASCII TABLE
*/
void ascii_to_nokia(unsigned char c, unsigned char big)
{
	unsigned char row;
	
	
		for (row=0;row!=5;row++)//5
		{
			bytefornokia=FontLookup[c][row];		// and get it				
			nokia_write_data();				// send data to nokia
		
		}
	        if(big)
	        {
	            	//beep
			beep(3,3);
			//delay
			hal_delay_us(50000);
	
	        }
              
	return;
}

/*

/*
    Writes a character on the LCD drive in decimal
*/
void LcdDec(int c)
{
	unsigned int temp;

        temp=c;
	//tentousends
	if ((c/10000)>0)  ascii_to_nokia((c/10000)+'0', 0);
	c-=(c/10000)*10000;

        temp=c; 
	//tousends
        if ((c/1000)>0)   ascii_to_nokia((c/1000)+'0', 0);
        c-=(c/1000)*1000; 
	
        temp=c;
        //hundreds
	if ((c/100)>0)    ascii_to_nokia((c/100)+'0', 0);
	c-=(c/100)*100;

	//tens
	if (((temp/10)>0) || ((temp/100)>0))  ascii_to_nokia((c/10)+'0', 0);
	c-=(c/10)*10;

	//ones
	ascii_to_nokia((c/1)+'0', 0);
	
	return;
}






/*
   Display byte in bin
*/
void LcdBin(unsigned char byte)
{
      
      unsigned char count=8;

      while(count --)
      {
           LcdDec((byte&128)?1:0);
           byte <<= 1;
      }
      
      return;
}



/*
    CLEAR DISPLAY
*/
void cls(void)
{
	int i;
	
        
	for(i=0; i != LCD_CACHE_SIZE; i++)
        {
                bytefornokia=0;
                LcdCache[i]=0;
                nokia_write_data();
        }
        nokia_gotoxy(0,0);
      	return;
}



void LcdPixel ( unsigned char x, unsigned char y, unsigned char mode )
{
    int  index;
    unsigned char  offset;
    unsigned char  data;

    if ( x > LCD_X_RES ) return;
    if ( y > LCD_Y_RES ) return;

    index = ((y / 8) * 84) + x;
    offset  = y - ((y / 8) * 8);

    data = LcdCache[index];

    if ( mode == PIXEL_OFF )
    {
        data &= (~(0x01 << offset));
    }
    else if ( mode == PIXEL_ON )
    {
        data |= (0x01 << offset);
    }
    else if ( mode  == PIXEL_XOR )
    {
        data ^= (0x01 << offset);
    }

    LcdCache[index] = data;

    if ( index < LoWaterMark )
    {
        //  Update low marker.
        LoWaterMark = index;
    }

    if ( index > HiWaterMark )
    {
        //  Update high marker.
        HiWaterMark = index;
    }
    
    return;
}

/*--------------------------------------------------------------------------------------------------

  Name         :  LcdLine

  Description  :  Draws a line between two points on the display.

  Argument(s)  :  x1, y1 -> Absolute pixel coordinates for line origin.
                  x2, y2 -> Absolute pixel coordinates for line end.
                  mode   -> Off, On or Xor. See enum.

  Return value :  None.

--------------------------------------------------------------------------------------------------*/
void LcdLine ( unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, unsigned char mode )
{
    int dx, dy, stepx, stepy, fraction;

    dy = y2 - y1;
    dx = x2 - x1;

    if ( dy < 0 )
    {
        dy    = -dy;
        stepy = -1;
    }
    else
    {
        stepy = 1;
    }

    if ( dx < 0 )
    {
        dx    = -dx;
        stepx = -1;
    }
    else
    {
        stepx = 1;
    }

    dx <<= 1;
    dy <<= 1;

    LcdPixel( x1, y1, mode );

    if ( dx > dy )
    {
        fraction = dy - (dx >> 1);
        while ( x1 != x2 )
        {
            if ( fraction >= 0 )
            {
                y1 += stepy;
                fraction -= dx;
            }
            x1 += stepx;
            fraction += dy;
            LcdPixel( x1, y1, mode );
        }
    }
    else
    {
        fraction = dx - (dy >> 1);
        while ( y1 != y2 )
        {
            if ( fraction >= 0 )
            {
                x1 += stepx;
                fraction -= dy;
            }
            y1 += stepy;
            fraction += dx;
            LcdPixel( x1, y1, mode );
        }
    }

   return; 
}







void LcdUpdate ( void )
{
    int i;

    if ( LoWaterMark < 0 )
        LoWaterMark = 0;
    else if ( LoWaterMark >= LCD_CACHE_SIZE )
        LoWaterMark = LCD_CACHE_SIZE - 1;

    if ( HiWaterMark < 0 )
        HiWaterMark = 0;
    else if ( HiWaterMark >= LCD_CACHE_SIZE )
        HiWaterMark = LCD_CACHE_SIZE - 1;

    //  Set base address according to LoWaterMark.
    bytefornokia = 0x80 | (LoWaterMark % LCD_X_RES);    	
    nokia_write_command();   
   
    bytefornokia = 0x40 | (LoWaterMark / LCD_X_RES);   	
    nokia_write_command();   
    
    
    //  Serialize the video buffer.
    for ( i = LoWaterMark; i <= HiWaterMark; i++ )
    {
	bytefornokia = LcdCache[i]; 	
    	 nokia_write_data();
    }

    //  Reset watermark pointers.
    LoWaterMark = LCD_CACHE_SIZE - 1;
    HiWaterMark = 0;

    return;
}


/*-----------------------------------------------------------------------------
  Name         :  LcdGotoXY
  Description  :  Sets cursor location to xy location corresponding to basic
                  font size.
  Argument(s)  :  x, y -> Coordinate for new cursor position. Range: 1,1..14,6
  Return value :  None.
-----------------------------------------------------------------------------*/
void LcdGotoXY ( unsigned char x, unsigned char y )
{
    LcdCacheIdx = (x - 1) * 6 + (y - 1) * 84;
}




/*-----------------------------------------------------------------------------
  Name         :  LcdChr
  Description  :  Displays a character at current cursor location
                  and increment cursor location.
  Argument(s)  :  size -> Font size. See enum.
                  ch   -> Character to write.
  Return value :  None.
-----------------------------------------------------------------------------*/
void LcdChr (unsigned char ch )
{
    unsigned char i;//, c;
    //byte b1, b2;
    //int  tmpIdx;

    if ( LcdCacheIdx < LoWaterMark )
    {
        //  Update low marker.
        LoWaterMark = LcdCacheIdx;
    }

    if ( (ch < 0x20) || (ch > 0x7b) )
    {
        //  Convert to a printable character.
        ch = 92;
    }

    //if ( size == FONT_1X )
    //{
        for ( i = 0; i < 5; i++ )//5
        {
            LcdCache[LcdCacheIdx++] = FontLookup[ch][i] << 1;//FontLookup[ch - 32][i] << 1;
        }
    //}
    /*
    else if ( size == FONT_2X )
    {
        tmpIdx = LcdCacheIdx - 84;

        if ( tmpIdx < LoWaterMark )
        {
            LoWaterMark = tmpIdx;
        }

        if ( tmpIdx < 0 ) return;

        for ( i = 0; i < 5; i++ )
        {
            c = FontLookup[ch - 32][i] << 1;
            b1 =  (c & 0x01) * 3;
            b1 |= (c & 0x02) * 6;
            b1 |= (c & 0x04) * 12;
            b1 |= (c & 0x08) * 24;

            c >>= 4;
            b2 =  (c & 0x01) * 3;
            b2 |= (c & 0x02) * 6;
            b2 |= (c & 0x04) * 12;
            b2 |= (c & 0x08) * 24;

            LcdCache[tmpIdx++] = b1;
            LcdCache[tmpIdx++] = b1;
            LcdCache[tmpIdx + 82] = b2;
            LcdCache[tmpIdx + 83] = b2;
        }

        //  Update x cursor position.
        LcdCacheIdx += 11;
    }
    */
    
    if ( LcdCacheIdx > HiWaterMark )
    {
        //  Update high marker.
        HiWaterMark = LcdCacheIdx;
    }

    //  Horizontal gap between characters.
    LcdCache[LcdCacheIdx++] = 0x00;
}






/*-----------------------------------------------------------------------------
  Name         :  LcdStr
  Description  :  Displays a character at current cursor location and increment
                  cursor location according to font size.
  Argument(s)  :  size    -> Font size. See enum.
                  dataPtr -> Pointer to null terminated ASCII string to display.
  Return value :  None.
-----------------------------------------------------------------------------*/
void LcdStr (unsigned char *dataPtr )
{
    while ( *dataPtr )
    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -