?? main._c
字號:
// ICC-AVR application builder : 2008-03-28
// Target : M16
// Crystal: 8.0000Mhz
// 編寫:wuyong Email:wuyong_ah@163.com
// 自做LED點陣屏專用驅(qū)動板與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)
// 上屏數(shù)據(jù)輸出 ---> 下屏數(shù)據(jù)輸入
#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的驅(qū)動代碼,根據(jù)138的真值表計算而來。
#pragma data: data
#define screen_size 8 //半屏顯示漢字個數(shù):8 32*128
uchar hanzi_size_S = 79; //上屏移動顯示漢字總個數(shù)
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); //左調(diào)整數(shù)據(jù)
void display_chinese(const uchar *p,uchar num);//靜態(tài)顯示
void display (void); //顯示數(shù)據(jù)刷新
#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)
/********************************************************
* 函數(shù)說明:595發(fā)送一個字節(jié)數(shù)據(jù) *
********************************************************/
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 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) //重復循環(huán)顯示
{
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(); //刷新顯示數(shù)據(jù)
HC595_lock_H; //鎖存為高,595鎖存信號
PORTA=sw[disrow]; //輸出行信號
delay_nus(200);
}
if(speed++>=0) //控制上屏移動顯示速度
{
speed=0 ;
if(Move++>=15)
{
Move=0; //16列移位計數(shù)器清零
zimo=zimo+32; //取字模計數(shù)器加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;
}
}
}
/*********************************************************
函數(shù)名:void Move_L(const uchar *p,uint f)
功能:緩存數(shù)據(jù) 左移
輸入:
輸出:
/*********************************************************/
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];
}
}
/*********************************************************
函數(shù)名: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];
}
}
/*********************************************************
函數(shù)名: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++) //發(fā)送16字節(jié)數(shù)據(jù)
{
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]); //發(fā)送數(shù)據(jù)
temp1++;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -