16 16点阵显示程序(含电路图)

2011-08-16 22:50:28来源: 互联网

以下是程序.

#include "config.h"

#define                DOTLED_LINE_PORT        PORTB
#define                DOTLED_LINE_DDR                DDRB
#define                DOTLED_LINE_PIN                PINB

#define                DOTLED_LINE_SCKT        PB1
#define                DOTLED_LINE_SCKH        PB5
#define                DOTLED_LINE_SDA                PB3

#define                DOTLED_ROW_PORT                PORTC
#define                DOTLED_ROW_DDR                DDRC
#define                DOTLED_ROW_PIN                PINC

#define                DOTLED_ROW_A0                PC0
#define                DOTLED_ROW_A1                PC1
#define                DOTLED_ROW_A2                PC2
#define                DOTLED_ROW_A3                PC3
#define                DOTLED_ROW_E                PC4



uint8 font[] = {
/*--  调入了一幅图像:这是您新建的图像  --*/
/*--  宽度x高度=16x16  --*/
0x00,0x00,0x00,0x00,0x08,0x38,0x18,0x44,0x08,0x44,0x08,0x04,0x08,0x08,0x08,0x10,
0x08,0x20,0x08,0x40,0x08,0x40,0x08,0x40,0x3E,0x7C,0x00,0x00,0x00,0x00,0x00,0x00
};



static void TransmitByte(uint8 byte);
static void SelectRow(uint8 row);
static void FlipLatchLine(void);


static void TransmitByte(uint8 byte)
{
        uint8 i;
        
        for(i = 0 ; i < 8 ; i ++)
        {
                if(byte & (1 << i))
                {
                        DOTLED_LINE_PORT |= _BV(DOTLED_LINE_SDA);
                }
                else
                {
                        DOTLED_LINE_PORT &= ~_BV(DOTLED_LINE_SDA);
                }
                //__delay_cycles(100);
                DOTLED_LINE_PORT |= _BV(DOTLED_LINE_SCKH);
                //__delay_cycles(100);
                DOTLED_LINE_PORT &= ~_BV(DOTLED_LINE_SCKH);
                //__delay_cycles(100);
        }
}

static void SelectRow(uint8 row)
{
          //row -= 1;
        row |= DOTLED_ROW_PIN & 0xe0;
        DOTLED_ROW_PORT = row;
}

static void FlipLatchLine(void)
{
        DOTLED_LINE_PORT |= _BV(DOTLED_LINE_SCKT);
        DOTLED_LINE_PORT &= ~_BV(DOTLED_LINE_SCKT);
}

void InitDotLedPort(void)
{
        DOTLED_LINE_PORT &= ~(_BV(DOTLED_LINE_SCKT) | _BV(DOTLED_LINE_SCKH));
        DOTLED_LINE_PORT |= _BV(DOTLED_LINE_SDA);
        DOTLED_LINE_DDR |= _BV(DOTLED_LINE_SCKT) | _BV(DOTLED_LINE_SCKH) | _BV(DOTLED_LINE_SDA);
        
        DOTLED_ROW_PORT |= 0x1f;
        DOTLED_ROW_PORT &= 0xf0;
        DOTLED_ROW_DDR |= 0x1f;
}
void EnableRow(boolean IsEnable)
{
        if(IsEnable)
        {
                DOTLED_ROW_PORT &= ~_BV(DOTLED_ROW_E);
        }
        else
        {
                DOTLED_ROW_PORT |= _BV(DOTLED_ROW_E);
        }
}
void PrintDotLed(uint8 * buffer)
{
        uint8 i , tmp;
        
        for(i = 0 ; i < 16 ; i ++)
        {
                tmp = *buffer ++;
                TransmitByte(~tmp);
                tmp = *buffer ++;
                TransmitByte(~tmp);
                SelectRow(i);
                FlipLatchLine();
        }
}
void main(void)
{
        InitDotLedPort();
        
        EnableRow(TRUE);
        
        while(1)
        {
                PrintDotLed(font);
                __delay_cycles(5000);
        }
        
}

//---------------------------------------------------------------------------
config.h文件

#ifndef        _CONFIG_H
#define        _CONFIG_H

//#define                GCCAVR

#define                CPU_CYCLES        7372800L




#ifndef                GCCAVR
#define                _BV(bit)        (1 << (bit))
#endif


#define                MSB                0x80
#define                LSB                0x01


#define                FALSE                0
#define                TRUE                1


typedef                unsigned char        uint8;
typedef                unsigned int        uint16;
typedef                unsigned long        uint32;
typedef                unsigned char        boolean;


#include avr.h>
#include 

#include "dotled.h"


#endif


//---------------------------------------------------------------------------

16 16点阵显示电路

关键字:电路图

编辑:神话 引用地址:http://www.eeworld.com.cn/mndz/2011/0816/article_11420.html
本网站转载的所有的文章、图片、音频视频文件等资料的版权归版权所有人所有,本站采用的非本站原创文章及图片等内容无法一一联系确认版权者。如果本网所选内容的文章作者及编辑认为其作品不宜公开自由传播,或不应无偿使用,请及时通过电子邮件或电话通知我们,以迅速采取适当措施,避免给双方造成不必要的经济损失。
论坛活动 E手掌握
微信扫一扫加关注
论坛活动 E手掌握
芯片资讯 锐利解读
微信扫一扫加关注
芯片资讯 锐利解读
推荐阅读
全部
电路图

小广播

独家专题更多

富士通铁电随机存储器FRAM主题展馆
富士通铁电随机存储器FRAM主题展馆
馆内包含了 纵览FRAM、独立FRAM存储器专区、FRAM内置LSI专区三大部分内容。 
走,跟Molex一起去看《中国电子消费品趋势》!
走,跟Molex一起去看《中国电子消费品趋势》!
 
带你走进LED王国——Microchip LED应用专题
带你走进LED王国——Microchip LED应用专题
 
电子工程世界版权所有 京ICP证060456号 京ICP备10001474号 电信业务审批[2006]字第258号函 京公海网安备110108001534 Copyright © 2005-2016 EEWORLD.com.cn, Inc. All rights reserved