TM1620芯片使用

芯片手册请使用半导体小芯进行查询:http://semiee.com/
半导体小芯

根据任务所需 需要用到TM1620芯片驱动RGB灯

原理图部分:
在这里插入图片描述
main.c

#include <STC8.H>
#include <stdio.h>
#include <intrins.h>
#include "TM1620.h"
sbit LED1=P2^6;
unsigned char i,j;
void delay_ms(unsigned int t)	;	//@24.000MHz
void main()
{
	P0M1 =0x00; P0M0 =0x00;
	P1M1 =0x00; P1M0 =0x00;
	P2M1 =0x00; P2M0 =0x00;
	P3M1 =0x00; P3M0 =0x00;
	P4M1 =0x00; P4M0 =0x00;
	P5M1 =0x00; P5M0 =0x00;
	RSTCFG|=0x10;P54RST: RST 管脚功能选择0:RST管脚用作普通I/O口(P54)1: RST 管脚用作复位脚
	
	for(i=0;i<12;i++)
	{
		STB=0;
		TM1620_WriteByte(0xc0+i); //传起始地址
		TM1620_WriteByte(0x00);    //传数据
		STB=1;
	}
	
	while(1)
	{
// RGB灯测试
#if 0
		for(i=1;i<=6;i++)
		{
			for(j=1;j<=6;j++)
			{
				TM1620_Dsplay(i,j);
				delay_ms(500);
			}
		}
#endif
		
// 全亮测试
#if 1
	DIN=1;
	CLK=1;
	STB=1;     //初始化
//  TM1620_WriteByte(0x00);
	TM1620_WriteByte(0x02);//显示模式设置,设置为6个GRID,8个SEG  
		STB=1;
	TM1620_WriteByte(0x44);//地址增加模式 固定地址
	STB=1;
	for(i=0;i<6;i++)
	{
		TM1620_WriteByte(0xC0+i*2); //传起始地址
		TM1620_WriteByte(0x3f);    //传数据  SEG1-SEG6  全选 为全亮
		STB=1;
	}
	TM1620_WriteByte(0x8a);     //显示控制命令  低三位控制亮度 数值越大亮度越大
	STB=1;
#endif	
	}
}

void delay_ms(unsigned int t)		//@24.000MHz
{
	unsigned char i, j;
	while(t--){
	_nop_();
	i = 32;
	j = 40;
	do
	{
		while (--j);
	} while (--i);}
}


TM1620.c

#include <STC8.H>
#include <stdio.h>
#include <intrins.h>
#include "TM1620.h"

	
unsigned long TmData;


void TM1620_WriteByte(unsigned char dat)
{ 
	unsigned char	i;
	STB=0;
	_nop_();_nop_();
	for(i=0;i<8;i++)
	{
		CLK=0;
		_nop_();_nop_();
		if((dat&0x01)!=0)
		{
			DIN=1;
		}
		else
		{
			DIN=0;
		}
		_nop_();_nop_();
		CLK=1;
		dat=dat>>1;
	}
	_nop_();_nop_();
}

void TM1620_Dsplay(unsigned char ch,unsigned dat)
{
	DIN=1;
	CLK=1;
	STB=1;
	TM1620_WriteByte(0x02);//显示模式设置,设置为6个GRID,8个SEG  
	STB=1;
	TM1620_WriteByte(0x44);//地址增加模式 固定地址
	STB=1;
	

	TM1620_WriteByte(startaddress+(ch-1)*2); //传起始地址
	TM1620_WriteByte(1<<(dat-1));    //传数据
	STB=1;
	
	TM1620_WriteByte(disconmode);     //显示控制命令
	STB=1;
}

TM1620.h

#ifndef __TM1620_H__
#define __TM1620_H__
sbit   STB    =P2^0;        //定义端口
sbit   CLK    =P4^2;
sbit   DIN    =P4^1;

#define dissetmode    0x02        //显示模式设置
#define writedatamode_z   0x40    //自动加一方式显存
#define writeledmode_z   0x41     //自动加一方式写LED显存命令
#define readkeymode    0x42       //读按键命令
#define readswmode    0x43        //读SW命令
#define writedatamode_g   0x44    //固定模式
#define writeledmote_g   0x45     //固定模式写LED显存命令
#define startaddress   0xc0       //起始地址
#define disconmode    0x8f        //显示控制

#define uchar unsigned char
void TM1620_WriteByte(unsigned char dat);
void TM1620_Dsplay(unsigned char ch,unsigned dat);
#endif

全亮测试(全亮为白色,设置脉冲宽度为 4/16)
请添加图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值