基于stc15f2k60s2芯片单片机编程(流动字幕)

本文介绍了如何在基于STC15F2K60S2芯片的单片机上实现流动字幕的功能。详细探讨了两种不同的实现方法,一种利用for循环,逻辑相对复杂;另一种则程序较长但逻辑简单,通过复制粘贴可快速实现。
摘要由CSDN通过智能技术生成

程序思路

一共两种方法,方法一用的是for循环实现的。逻辑比较复杂。第二种方法逻辑比较简单,但是程序很长。其实复制粘贴的话,也不是太麻烦。具体程序如下:

流动字幕①

#include<stc15f2k60s2.h>
#include<intrins.h>
int a,n=0,i=0;
unsigned int shuzu1[]={
   0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0xff,0x80,0x90};
unsigned int shuzu2[]={
   0xc0,0xf8,0x82,0x92,0x99,0xb0,0xa4,0xf9,0x80,0XFF,0x90};
void delay1ms();


void main()
{
   
	
 P2=0XA0;P0=0X00;P2=0X80;P0=0XFF;
	while(1)
	{
   
		 a++;
	 if(a==100)
	 {
   
	  a=0;
		 i++;
	 }
	 if(i<=7)
	 {
   
   for(n=0;n<=i;n++)
	 {
   		 
	 P2=(P2&0X1F)|0Xc0;
	P0=0X80>>n;
	P2&=0X01;
	P2=(P2&0X1F)|0Xe0;
	P0=0XFF;
	P0=shuzu1[i-n];
	P2&=0X1F;
	 delay1ms();
	 }
   }
	 if(i>8)
	 {
   
    for(n=0;n<(16-i);n++)
	 {
   		 
	 P2=(P2&0X1F)|0Xc0;
	P0=0X01<<n;
	P2&=0X01;
	P2=(P2&0X1F)|0Xe0;
	P0=0XFF;
	P0=shuzu2[16-i-n];
	P2&=0X1F;
	 delay1ms();
	 }
  }
	 if(i==16)
		 i=0;
}
}
void delay1ms()		//@11.0592MHz
{
   
	unsigned char i, j;

	_nop_();
	_nop_();
	_nop_();
	i = 11;
	j = 190;
	do
	{
   
		while (--j);
	} while (--i);
}

流动字幕②

#include <stc15f2k60s2.h>
#include <intrins.h>
void Timer0Init()	;
void zhduan();
void Delay500ms(
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值