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

📄 main.c

📁 基于mega16的 128X64点阵驱动程序
💻 C
字号:
// ICC-AVR application builder : 2008-03-28
// Target : M16
// Crystal: 8.0000Mhz
// 编写: 烈火狂龙    参考: xiaoden 51点阵屏驱动
// Email:fire.dragon.avr@163.com


// 自做LED点阵屏专用驱动板与LED 点阵屏接口定义
// A    --->  PA0               B    --->   PA1
// C    --->  PA2               D!   --->   PA3
// D    --->  PA4               SC   --->   PC7(595_clk)
// RC   --->  PC6(595_lock)     DATA1--->   PD7(595_data)
// DATA2--->  PD6(595_data)
// 上屏数据输出 ---> 下屏数据输入

#include <iom16v.h>
#include <macros.h>
#include <delay.h>
#include "hanzi.h"

#define uchar unsigned char
#define uint  unsigned int

extern const uchar QQ[];      //QQ图片
extern const uchar OURAVR[];  //OURAVR
extern const uchar hello[];   //hello!

const uchar sw[16]={0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10,
                    0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x08,}; //156的驱动代码,根据138的真值表计算而来。

#pragma data: data

#define screen_size    8            //半屏显示汉字个数:8  32*128
uchar hanzi_size_S = 79;            //上屏移动显示汉字总个数

uchar BUFF[screen_size*2];			//缓存
uchar BUFF_1[screen_size*2];		//缓存                    
uchar disrow;                       //disrow 为16行变量
uchar Move;
uchar speed;
uchar flash_cnt;
uchar flash_flag;
uint  zimo;
uchar display_flag=0;

void Move_L(const uchar *p,uint f); //左调整数据  
void display_chinese(const uchar *p,uchar num);//静态显示
void display (void);                //显示数据刷新

#define     HC595_data1_H()     PORTD |= BIT(PD7)
#define     HC595_data1_L()     PORTD &=~BIT(PD7)
#define     HC595_data2_H()     PORTD |= BIT(PD6)
#define     HC595_data2_L()     PORTD &=~BIT(PD6)

#define     HC595_clk_H         PORTC |= BIT(PC7)
#define     HC595_clk_L         PORTC &=~BIT(PC7)

#define     HC595_lock_H        PORTC |= BIT(PC6)
#define     HC595_lock_L        PORTC &=~BIT(PC6)

/********************************************************
*             函数说明:595发送一个字节数据             *
********************************************************/
void HC595_send_2byte(uchar byte1,uchar byte2)
{
 uchar i;
 
 HC595_lock_L;
 for (i=0x01;i!=0;i=i<<1)
  {
   if(byte1&i)
      HC595_data1_H();
   else
      HC595_data1_L();
   if(byte2&i)
	  HC595_data2_H();
   else
	  HC595_data2_L();
   
   HC595_clk_L;
   HC595_clk_H;
   }
}

/*********************************************************
函数名:void Move_L(const uchar *p,uint f)
功能:缓存数据 左移
输入:
输出:
/*********************************************************/                    
void Move_L(const uchar *p,uint f)
{
 signed char s;
	for(s=screen_size;s>=0;s--)		//
	{
	 BUFF[2*s+1]=p[f+32*s+2*disrow];			 
	 BUFF[2*s]=p[f+1+32*s+2*disrow];	    
	}
}	

/*********************************************************
函数名:void display_chinese(const uchar *p,uchar num)
功能:显示汉字
输入:
输出:
/*********************************************************/ 
void display_chinese(const uchar *p,uchar num)
{
 uchar s;
 for(s=0;s<screen_size;s++)
	{
	 BUFF_1[2*s]=p[1+32*(s+num)+2*disrow];
	 BUFF_1[2*s+1]=p[32*(s+num)+2*disrow];
	}
}

/*********************************************************
函数名:void display(void)
功能:显示刷新
输入:
输出:
/*********************************************************/ 
void display(void)
{
  uchar i = Move;
  uchar s;
  uchar inc,tempyid,temp,temp1=0;
  
  if(i<8)
    inc=0;
  else 
    inc=1;
  for(s=0+inc;s<screen_size*2+inc;s++)        //发送16字节数据
	{
	  if(i<8) 
        tempyid=i;
      else 
       tempyid=i-8;
      temp=((BUFF[s]>>tempyid)|(BUFF[s+1]<<(8-tempyid)));
      HC595_send_2byte(temp,BUFF_1[temp1]);    //发送数据	
	  temp1++;
	}
}


void port_init(void)
{
 PORTA = 0x00;
 DDRA  = 0xFF;
 
 PORTB = 0x00;
 DDRB  = 0xFF;
 
 PORTC = 0x00; //m103 output only
 DDRC  = 0xFF;
 
 PORTD = 0x00;
 DDRD  = 0xFF;
}

//call this routine to initialize all peripherals
void init_devices(void)
{
 //stop errant interrupts until set up
 CLI(); //disable all interrupts
 port_init();

 MCUCR = 0x00;
 GICR  = 0x00;
 TIMSK = 0x00; //timer interrupt sources
 SEI(); //re-enable interrupts
 //all peripherals are now initialized
}


void main(void)
{
 init_devices();
 //insert your functional code here...

 while(1)                           //重复循环显示
  {
	 for(disrow=0;disrow<16;disrow++)
		 {
		  PORTA=0x18;                //关闭显示,消影
		  
		  Move_L(OURAVR,zimo);       //上屏移动显示OURAVR
		  
		  if(flash_flag==0)
			display_chinese(hello,0);//下屏显示hello
		  else
		    display_chinese(QQ,0);   //下屏picture
			
		  display();                 //刷新显示数据
	
	      HC595_lock_H;			     //锁存为高,595锁存信号
	      PORTA=sw[disrow];			 //输出行信号
	   
	      delay_nus(200);
          }			
		  
	if(speed++>=0)           //控制上屏移动显示速度
	  {
	    speed=0 ;
	    if(Move++>=15)
         {
		  Move=0;            //16列移位计数器清零    
          zimo=zimo+32;      //取字模计数器加32,准备下一个字
	      if(zimo>=(hanzi_size_S*32)) //字模是否到最后来。
			 zimo=0;          //从头在来。 
   	  	  }
	   } 
	     
	if(flash_cnt++>=100)//下屏显示切换时间
	  {
	   flash_cnt=0;
	   if(flash_flag==0)
	      flash_flag=1;
	   else
	      flash_flag=0;
	   }
	   
   }

}

⌨️ 快捷键说明

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