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

📄 main.c

📁 用AT91RM9200控制信利的LCD
💻 C
字号:
//*----------------------------------------------------------------------------
//*         ATMEL Microcontroller Software Support  -  ROUSSET  -
//*----------------------------------------------------------------------------
//* The software is delivered "AS IS" without warranty or condition of any
//* kind, either express, implied or statutory. This includes without
//* limitation any warranty or condition with respect to merchantability or
//* fitness for any particular purpose, or against the infringements of
//* intellectual property rights of others.
//*----------------------------------------------------------------------------
//* File Name           : main.c
//* Object              : Basic twi example. Write a byte into EEPROM and read it
//* Creation            : NL   25/11/02
//*
//*----------------------------------------------------------------------------
#include "main.h"

#define AT91_SYS                ((AT91PS_SYS) AT91C_BASE_SYS)
#define LcdCom         *(volatile unsigned char *)0x50000004
#define LcdData        *(volatile unsigned char *)0x50000000   

unsigned long temp = 0;
unsigned char Data[] = {    
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
       
        } ;
   //    unsigned int valR1 = 0x10;
   unsigned int valR5 = 0x1e;
   unsigned int valR7 = 0x7e;
   unsigned int valR6 = 0;
  
#define AT91C_SM_RWHOLD   (0 << 28)
#define AT91C_SM_RWSETUP  (0 << 24)
#define AT91C_SM_ACESS    (0 << 16)               /* orig = 0 */
#define AT91C_SM_DRP      (0 << 15)               /* orig = 0 */
#define AT91C_SM_DBW      (2 << 13)               /* orig = 0 */
#define AT91C_SM_BAT      (1 << 12)               /* orig = 0 */
#define AT91C_SM_TDF      (0 << 8)                /* orig = 0 */
#define AT91C_SM_WSEN     (1 << 7)                /* orig = 1 */
#define AT91C_SM_NWS      (80)                    /* orig = 0 */
unsigned long var;      
 
void delay()
{
	for(temp=0;temp<50;temp++)
	{
		;
	}
}

void ReadySTA01()     //读状态并判断STA0,STA1状态准备好
{
	unsigned long flag = 1;
	
	while((flag & 0x3) != 3)
	{
		//AT91_SYS
		flag = LcdCom;
		delay();

	}
}

void ReadySTA3()     //读状态并判断STA3状态准备好
{
	unsigned long flag = 1;
	while((flag & (1 << 3)) == 0)
		flag = LcdCom;
}

void LcdClr()
{
	unsigned int R6;
	
	ReadySTA01();
	LcdData = 0x00;
	ReadySTA01();
	LcdData = 0x00;
	ReadySTA01();
	LcdCom = 0x24;

	//ReadySTA01();
	//LcdCom = 0xb0;
	
	for(R6=0;R6<0x2000;R6++)
	{	
		//ReadySTA3();
		//LcdData = 0x00;
		ReadySTA01();
		LcdData = 0xf0;
		ReadySTA01();
		LcdCom = 0xc0;
	}
	//ReadySTA3();
	//LcdCom = 0xb2;
}

unsigned char Val;
int main()
{
		
	// AT91_SYS->EBI_CSA &= ~(1 << 4); 
	 //c/d------ADDR0
     AT91_SYS->EBI_SMC2_CSR[4] = (AT91C_SM_RWHOLD | AT91C_SM_RWSETUP | AT91C_SM_ACESS |
   								AT91C_SM_DRP    | AT91C_SM_DBW     | AT91C_SM_BAT   |
                                AT91C_SM_TDF    | AT91C_SM_WSEN    | AT91C_SM_NWS);
	
	//Text home address set
	
//	while(1)
//	{
	
	//  LcdCom=0x55;
//	  Val=LcdCom;
//			}

	ReadySTA01();
	LcdData = 0x00;
	ReadySTA01();
	LcdData = 0x00;
	ReadySTA01();
	LcdCom  = 0x40;
	
	
	//Text area set
	ReadySTA01();
	LcdData = 0x1E;
	ReadySTA01();
	LcdData = 0x00;
	ReadySTA01();
	LcdCom  = 0x41;
	
	
	//Graphic home address set
	ReadySTA01();
	LcdData = 0x10;
	ReadySTA01();
	LcdData = 0x00;
	ReadySTA01();
	LcdCom  = 0x42;
	
	
	//Graphic area set
	ReadySTA01();
	LcdData = 0x10;
	ReadySTA01();
	LcdData = 0x00;
	ReadySTA01();
	LcdCom  = 0x43;
	
	
	//"OR" mode
	ReadySTA01();
	LcdCom = 0x80;  //or
	
	
	//Cursor pattern set 3 lines
	ReadySTA01();
	LcdCom = 0xa3;
	
	while(1)
	{
	
	//ReadySTA01();
	//LcdCom = 0x90;  //display off
	LcdClr();  //clear display start to test
	
	ReadySTA01();
	LcdData = 0x10;
	ReadySTA01();
	LcdData = 0x0e;
	ReadySTA01();
	LcdCom = 0x24;
	
	ReadySTA01();
	LcdCom = 0x98; 
	
	ReadySTA01();
	LcdCom = 0xf9;
	
	ReadySTA01();
	LcdCom = 0xfb;
	
	ReadySTA01();
	LcdCom = 0xfd;
	ReadySTA01();
	LcdCom = 0xff;
	

   ReadySTA01();
LcdCom = 0x94;  //text on graphic off
		
	//box
	ReadySTA01();
	LcdData = 0x00;
	ReadySTA01();
	LcdData = 0x80;
	ReadySTA01();
	LcdCom = 0x24;
	ReadySTA01();
	LcdCom = 0xb0;
	
	valR5 = 0x1e;
	while(valR5)
	{
		ReadySTA3();
		LcdData = 0xff;
		valR5--;
	}
	valR7 = 0x7e;
	while(valR7)
	{
		ReadySTA3();
		LcdData = 0x80;
		
		valR6 = 0x1c;
		while(valR6)
		{
			ReadySTA3();
			LcdData = 0x00;
			valR6--;
		}
		
		ReadySTA3();
		LcdData = 0x01;
		valR7--;
		
	}
	
	valR5 = 0x1e;
	while(valR5)
	{
		ReadySTA3();
		LcdData = 0xff;
		valR5--;
	
	}
	
	ReadySTA3();
	LcdCom = 0xb2;
	
	ReadySTA01();
	LcdCom = 0x94;  //text on graphic off
		
	//	ReadySTA01();
	//	LcdCom = 0xa3;
		
	ReadySTA01();
	LcdCom = 0x98;  //text off graphic on
		
  
	ReadySTA01();
	LcdCom = 0x90;  //display off
    
    ReadySTA01();
	LcdCom = 0x9c;  //text on graphic on

	}
	
	
	/* test
	ReadySTA01();
	LcdData = 0x00;
	ReadySTA01();
	LcdData = 0x04;
	ReadySTA01();
	LcdCom = 0x24;
	ReadySTA01();
	LcdCom = 0xb0;



*/


	/*  
	while(valR1)
	{
		unsigned int valR2 = 0x08;
		unsigned int idata = 0;
		
		while(valR2)
		{
			unsigned int valR3 = 0x1e;
			
			while(valR3)
			{
				ReadySTA3();
				LcdData = Data[idata];
				valR3--;
			}
			
			idata++;
			valR2--;
		}
		
		valR1--;	
	}
	
	ReadySTA01();
	LcdCom = 0xb2;
	
*/	
	while(1)	// Set sequential part here
	{
		
	//	var = *(volatile unsigned long *)AT91_BASE_NCS4;
	//	*(volatile unsigned long *)AT91_BASE_NCS4 = 0x000000ff; 
		delay();
	}
	
}

⌨️ 快捷键说明

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