四极管 点阵屏控制 AVR 静态点阵

595控制的

#include <avr/io.h>
#include <avr/delay.h>
//时钟定为16MHz,F_CPU=1600000
#include "MyBit.h"


#define uint  unsigned int
#define uchar unsigned char

#define  port154  PORTB//154= '

#define  sda  OA0
#define  g    OA1
#define  rck  OA2
#define  scl  OA3

#define H 16	//行-bit
#define L 48	//字节

#define TCNT0_init  200

const uchar DISP[];

volatile uint line=0;
volatile uint erect=0;

volatile uchar DDRAM[H][L]={
	0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
	0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
	0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
	                                                                             
	0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
	0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
	0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
	                                                                             
	0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
	0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
	0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,
	                                                                             
	0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,
	0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,
	0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,
	                                                                             
	0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,
	0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,
	0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,
	                                                                             
	0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,
	0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,
	0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,
	                                                                             
	0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,
	0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,
	0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,
	                                                                             
	0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,
	0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,
	0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,
	                                                                             
	0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,
	0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,
	0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,
	                                                                             
	0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,
	0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,
	0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,
	                                                                             
	0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,
	0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,
	0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,0x3f,0xf8,
	                                                                             
	0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,
	0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,
	0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,
	                                                                             
	0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,
	0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,
	0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,
	                                                                             
	0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,
	0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,
	0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,0x01,0x02,
	                                                                             
	0x00,0xfe,0x00,0xfe,0x00,0xfe,0x00,0xfe,0x00,0xfe,0x00,0xfe,0x00,0xfe,0x00,0xfe,
	0x00,0xfe,0x00,0xfe,0x00,0xfe,0x00,0xfe,0x00,0xfe,0x00,0xfe,0x00,0xfe,0x00,0xfe,
	0x00,0xfe,0x00,0xfe,0x00,0xfe,0x00,0xfe,0x00,0xfe,0x00,0xfe,0x00,0xfe,0x00,0xfe,
	                                                                             
	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,
	};

void timer0_init(void);
void test();
void shift_8bit(uchar shiftdata);
void maindelay()
{
	unsigned long i;
	for(i=0;i<100000;i++);
	}
//主程序开始
int main(void)
{

    //IO Initial
    DDRA  =0xff;
    DDRB  =0xff;
    DDRC  =0xff;
    DDRD  =0xff;
    PORTA =0xFF;									//不用的管脚使能内部上拉电阻。
    PORTB =0xFF;
    PORTC =0xFF;
    PORTD =0xFF;
    
		timer0_init();
		
	//	test();		
		
		TIMSK = (1<<TOIE0); 				//使能T0中断(作定时用)
  	sei();											//使能全局中断
  	while(1);
}
void timer0_init(void) //CTC模式输出1KHz/2KHz方波
{
 //TOP=12000000/(2*64*2000)-1=45.875 选46  2.016KHz(0.496ms)
 TCCR0 = (0<<CS02)|(0<<CS01)|(1<<CS00);
}
//T0溢出中断服务子程序
SIGNAL(SIG_OVERFLOW0)//定时器/计数器 0 溢出中断
{
	TIMSK = (0<<TOIE0);
	TCNT0=TCNT0_init;
	while(1){
	for(line=0;line<16;line++){
	//g=1;
	rck=0;//595开关闭合
	for(erect=0;erect<L;erect++)//字节单位
		{
		shift_8bit(DDRAM[line][erect]); 
		} //送完一行
		rck=1;//每送完一行,595开关打开一次
		rck=0;//关闭RCK
		port154=line;
		g=0;
		//line+=1;
		//if(line==16){line=0;}//送完一屏 	
	}
}
	TIMSK = (1<<TOIE0);
}
//595驱动
void shift_8bit(uchar shiftdata)
{
  uchar i;
  scl=0;
  for(i=0;i<8;i++)
  {   
    if((shiftdata<<i)&0x80)  sda=1;
    else                     sda=0; 	
    scl=1;        
    scl=0;
  } 
}
//first test
/*void test()
{
	uint line=0,erect,i;
	g=0;
	for(line=0;line<H;line++)
	{
		for(erect=0;erect<L;)
		{
			DDRAM[line][erect]=DISP[(erect/2)*32+line];
			DDRAM[line][erect+1]=DISP[((erect+1)/2)*32+line+1]; 
			erect+=2;
		}
	}
	while(1)
	{
		rck=0;//595开关闭合
		for(erect=0;erect<L;erect++)//字节单位
			{
				shift_8bit(DDRAM[line][erect]); 
			} //送完一行
			rck=1;//每送完一行,595开关打开一次
			_delay_us(2);
			rck=0;//关闭RCK
			port154=line;
			line+=1;
			if(line==16){line=0;}//送完一屏 
	}
}*/


 

转载请注明出处。作者:四极管。广西师范大学 电子工程学院大学生科技创新基地 邮箱: yangxingbo-0311@163.com

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值