⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hdp.c

📁 通过人眼视觉暂停来显示图片文字
💻 C
字号:
//====================================================================================
// HDP.c  晃动屏程序  
//====================================================================================
// 
// 版权所有: Copyright (C) 2007 Wellsin Studio
// 编    写: 老  酷
// 版    本: V1.0
// 日    期: 2007-08-09
// 目标器件: C8051F330D
// 开发工具: KEIL 'c'
//
//====================================================================================
// 包含文件
//====================================================================================
#include <c8051f330.h>
#include <5x8_ascii_dot.c>
//====================================================================================
// 常数预定义
//====================================================================================
#define BYTE unsigned char
#define WORD unsigned int
//====================================================================================
// 端口定义
//====================================================================================
sbit KEY1 = P0^7;
sbit KEY2 = P1^7;
sbit KEY3 = P2^0;

#define G_Port P0
#define R_Port P1
//====================================================================================
// 全局变量
//====================================================================================
BYTE str1[8]={"LAO KU  "};
BYTE color;
//====================================================================================
// 函数原形
//====================================================================================
void PORT_Init (void);
void Reset_Sources_Init();

Delay_ms(WORD ms);
//====================================================================================
// 主程序
//====================================================================================
void main (void) 
{ 
  OSCICN    = 0x81;           // 初始化系统时钟
  PCA0MD &= ~0x40;                    // 禁止WDT 
  PORT_Init ();                       // 端口初始化
  Reset_Sources_Init();               // 复位源初始化                          
  TCON=0x01;
  IE        = 0x81;
  IT01CF    = 0x07;
  color=1;					      
  while(1)
    {
      if(!KEY2)    // 判断是否有键按下
        {
          Delay_ms(100);       // 延时消抖动
          if(!KEY2) 
            {                  
              while(!KEY2){};  // 等待键放开
 		      color++;              // 改变颜色
		      if(color>3){color=1;}
		      R_Port=G_Port=0xFF;
		      switch(color)  // 确定颜色
	            {
		          case 1: R_Port=0x80; break; // 红
		          case 2: G_Port=0x80; break; // 绿
		          case 3: R_Port=G_Port=0x80; break; // 红+绿=黄
		          default:break;
	            }
            }
        }	  
    }
}
//====================================================================================
// 中断服务程序
//====================================================================================
//----------------------------
// 外部中断0程序
//----------------------------
void INT0_ISR (void) interrupt 0
{
BYTE i,j,outbuf;
WORD dot;
  R_Port=0xFF;
  G_Port=0xFF;
  Delay_ms(450);
  for(i=0;i<8;i++)
    {
	  dot=(str1[i]-0x20)*5; // 计算字符在点阵中的首地址
	  for(j=0;j<5;j++)
        {                // 一个字符5列
		  outbuf=~(ASCII_Dot[dot+j]>>1);
	      switch(color)  // 确定颜色
	        {
		      case 1: R_Port=outbuf; break; // 红
		      case 2: G_Port=outbuf; break; // 绿
		      case 3: R_Port=G_Port=outbuf; break; // 红+绿=黄
		      default:break;
	        }
	      Delay_ms(15);
	      R_Port=G_Port=0xFF;
	      Delay_ms(5);
	    }   
	  Delay_ms(15);
	}
	IE0=0;
}
//====================================================================================
// 子程序
//====================================================================================

//----------------------------------------
// 延时子程序
//----------------------------------------
// 
Delay_ms(WORD ms)
{
WORD i;
  while(ms!=0)
    {
      for(i=50;i>0;i--){} 
	  ms--;
	}
}
//----------------------------------------
// 端口初始化
//----------------------------------------
void PORT_Init (void)
{ 
   XBR1   = 0x40;   // 交叉开关打开
   P0MDOUT   = 0x7F;
   P1MDOUT   = 0x7F; 
  
   P0SKIP  = 0x0B;
}
//----------------------------------------
// 复位源初始化
//----------------------------------------
void Reset_Sources_Init()
{
WORD i;
    i = 0;
    VDM0CN    = 0x80;  // 允许内部电压监视器
    for (i = 0; i < 350; i++);  // 延时等待电压监视器稳定
    RSTSRC    = 0x06;  //  允许电压监视器复位、时钟丢失复位
}
//====================================================================================
//                                  结 束
//====================================================================================

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -