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

📄 zlcd.c

📁 &#8226 控制器(CPU): Atmel AT90S8515 AVR &#8226 MP3解码器: STA013 &#8226 音频 DAC: CS4334 &#8226 IDE 接口
💻 C
字号:
/*
    Copyright 2003 Nasif Akand (nasif@yifan.net)
    http://go.to/zipamp
    http://zipamp.virtualave.net

    This file is part of ZipAmp MP3 software.

    ZipAmp is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    ZipAmp is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this code; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*/

//This module performs LCD operations for ZipAmp
//Nasif Akand

//If using CodeVision then following includes aren't needed.
//#include "zcontrol.h"
//#include "zfat.h"
//#include "zata.h"
//#include "ztype.h"
//#include "i2c.h"
//#include "<delay.h>" //CodeVision AVR internal delay routines
#include "zlcd.h"


#define	clkDelay	delay_us(2);
#define delayLong	delay_us(40);

void SetNibble(byte value) {
//Write data on 4 bits for LCD

 OutMode;
 PORTC.0= value & 0x01;
 PORTC.1= (value >> 1) & 0x01;
 PORTC.2= (value >> 2) & 0x01;
 PORTC.3= (value >> 3) & 0x01;
}

void WriteByte(byte value) {
//Writes byte, nibble at a time

 SetNibble(value>>4);
 EN=1;
 clkDelay;
 EN=0;
 clkDelay;
 SetNibble(value);
 EN=1;
 clkDelay;
 EN=0;
 clkDelay;
 delay_us(40);
}

/*
byte ReadByte() {
 byte value;
 InMode;
 EN=0;
 clkDelay;
 EN=1;
 value = GetNibble();
 EN=0;
 clkDelay;                     
 EN=1;
 value = (value<<4) + GetNibble();
}


void WaitTillLCDBusy() {
 byte value;
 do {
  EN=1;	//Start LCD command
  RS=0;	//Its a command
  RW=1;	//Its a command
  value=ReadByte();  
 }
 while ((value & 0x80)== 0x80); //Busy is bit 7 set
 RW=0;
}*/

void InitLCD() {
//Initialize LCD, then print logo

 byte i;
 OutMode;
 RS=0;
 RW=0;
 EN=0;
 clkDelay;
 EN=1;
 SetNibble(2);	//Set 4 bit mode
 EN=0;
 clkDelay;
 delayLong;
 WriteByte(0x28);	//Function Set
 LCDclrscr();		//clearscreen
 WriteByte(0x0C);	//display on, cursor off
 WriteByte(0x40);	//Set CGram addres;
 RS=1;                                   
 for(i=0;i<64;i++) WriteByte(cg[i]); 	//load CGRAM characters
// for(i=0;i<8; i++) WriteByte(cgleftTop[i]); 
// for(i=0;i<8; i++) WriteByte(cgrightTop[i]);
// for(i=0;i<8; i++) WriteByte(cgleftBottom[i]);
// for(i=0;i<8; i++) WriteByte(cgrightBottom[i]);
 RS=0;                          
 
 //Printing Logo
 LCDclrscr();
 writechar(0);
 for(i=0;i<10;i++) writechar('=');
 writechar(1);
 gotoxy(1,0); writechar('|');
 gotoxy(1,11); writechar('|');
 gotoxy(2,0);
 writechar(2);
 for(i=0;i<10;i++) writechar('=');
 writechar(3);
 gotoxy(1,3);            
 writestring("ZipAmp");
 gotoxy(1,16);
 writestring("v2.0"); //three space version info
 gotoxy(2,12);
 writestring("(c)Nasif");
 gotoxy(3,1);
 writestring("http://go.to/zipamp");
}

void SetSoundCg() {
//Load sound bar graph CGRAM characters
 byte i; RS=0; RW=0;                               
 WriteByte(0x40);	//Set CGram addres; 
 RS=1;   
 for(i=0;i<32;i++) WriteByte(soundCg[i]); 	//load CGRAM characters 0..3
 RS=0;                          

}

void writechar(byte value) {
//Write 1 character
 #asm("cli");
 RS=1; RW=0; //EN=0;
 WriteByte(value);
 RS=0;
 Hi_Z;
 #asm("sei"); 
}

void writestring(byte flash *strn) {
//Write a string from flash ROM
 while (*strn!=0) writechar(*strn++); 
}

void gotoxy(byte line, byte position) { 
//Gotoxy function. X=line number, Y=character position

 byte address;
 OutMode;
 RS=0;
 RW=0;
 address=0x80+lcdLineStart[line]+position;
 WriteByte(address);
}
              
void LCDclrscr() {
//Clear LCD
 OutMode;
 RS=0; RW=0;
 WriteByte(0x01);
 delay_ms(2);
}

void writeNumber(word value) {
//Write a decimal number on LCD

 byte temp[8],i=0; 
 do {
  temp[i++]=value%10;
  value=value/10;
 }
 while (value>0); 
 for(;i>0;) writechar(temp[--i]+48); //start from back and print the number
}

void blink() { 
//Setup curson blink, based on player state
 #asm("cli");
 OutMode;
 RS=0;
 RW=0;
 WriteByte(0x0C + (play & 1)); //if Play = 1 blink on, if play=0 blink off
}

/*
void clreol(byte line) {
// gotoxy(line,0);
 spacer(line,0,20);
// gotoxy(line,0);
}

void spacer(byte x, byte y, byte value) {
 byte i;                    
 gotoxy(x,y);
 for(i=0;i<value;i++) writechar(' ');
 gotoxy(x,y);
} */                                    
/*
void writehex(byte val) {

 byte temp[2],i=0;
 for(i=0;i<2; i++){
  temp[i]=val % 0x10;
  val=val/0x10;
 }
 for (i=2; i>0; i--) {
  if (temp[i-1]>9) temp[i-1] += 0x37;
  else temp[i-1]+=0x30;
  writechar(temp[i-1]);
  //cout<<temp[i-1];
 } 
}
*/

⌨️ 快捷键说明

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