📄 yc_play.c
字号:
/*===========================================================================
【项目名】: 遥控渐变选色程序
【文件名】: YC_Play
【名 称】: 主文件
【版 本】: 1.0
【组 织】:
【作 者】: 周盛志
【E-mail】: zhounanxu@163.com
===========================================================================*/
#include <avrx/avrx.h>
#include <avr/eeprom.h>
#include "YC_MainFile.h"
#include "Hardware.h"
#include "YC_Play.h"
BYTE bLastPlayIdx EEPROM;
WORD bColorAsh[5][3] EEPROM;
WORD WASHVAL=2048; //灰度值
WORD wCurRedAsh, wCurGreAsh, wCurBluAsh;
WORD wCurRedAshVal, wCurGreAshVal, wCurBluAshVal;
BYTE bCurPlayIdx = 1;
struct WORKFLAG
{
BYTE bColseWork; //关机标志,1=关机,0=开机;
BYTE bKeyUpt; //按键状态标志,1=有键按下,0=无键按下;
BYTE bAshExit; //灰度播放快速退出标志,1=有效,0=无效;
BYTE bSaveKeyC; //保存按键C按下标记,1=有效,0=无效;
BYTE bPlayAshOld; //上一节目是否灰度播放标志.
}WorkFlag;
/*=====================================================================
【功 能】: 重迭1/2周期RGB三角波渐变.
【名 称】: Play_Gradual(BYTE bGradSpeeds)
【日 期】: 2006年8月30日
=====================================================================*/
void Play_Gradual(BYTE bGradSpeeds)
{
WORD wi, wj;
WorkFlag.bPlayAshOld = 1;
for(wi = 0; wi < WASHVAL; wi++)
{
if(WorkFlag.bAshExit == 1)
{WorkFlag.bAshExit = 0;return;}
for(wj=0; wj<bGradSpeeds; wj++)
{
wCurRedAsh = wi;
wCurGreAsh = WASHVAL-wi;
wCurBluAsh = 0;
PlayStaticAsh(wCurRedAsh, wCurGreAsh, wCurBluAsh);
}
}
for(wi=0; wi<WASHVAL; wi++)
{
if(WorkFlag.bAshExit == 1)
{WorkFlag.bAshExit = 0;return;}
for(wj=0; wj<bGradSpeeds; wj++)
{
wCurRedAsh = WASHVAL-wi;
wCurGreAsh = 0;
wCurBluAsh = wi;
PlayStaticAsh(wCurRedAsh, wCurGreAsh, wCurBluAsh);
}
}
for(wi=0; wi<WASHVAL; wi++)
{
if(WorkFlag.bAshExit == 1)
{WorkFlag.bAshExit = 0;return;}
for(wj=0; wj<bGradSpeeds; wj++)
{
wCurRedAsh = 0;
wCurGreAsh = wi;
wCurBluAsh = WASHVAL-wi;
PlayStaticAsh(wCurRedAsh, wCurGreAsh, wCurBluAsh);
}
}
}
/*=====================================================================
【功 能】: 播放某一RGB灰度颜色
【名 称】: PlayStaticAsh(WORD wRedAsh, WORD wGreenAsh, WORD wBlueAsh)
【日 期】: 2006年8月30日
=====================================================================*/
void PlayStaticAsh(WORD wRedAsh, WORD wGreenAsh, WORD wBlueAsh)
{
WORD wi;
for(wi=0; wi<WASHVAL; wi++)
{
if(wi < wRedAsh)
ON_Red();
else
OFF_Red();
if(wi < wGreenAsh)
ON_Gre();
else
OFF_Gre();
if(wi < wBlueAsh)
ON_Blu();
else
OFF_Blu();
}
}
/*=====================================================================
【功 能】: 遥控按键处理
【名 称】: KeyYc()
【日 期】: 2006年8月30日
=====================================================================*/
void KeyYc(BYTE bKeyVal)
{
if(bKeyVal == ONOFF_KEYA)
{WorkFlag.bColseWork = !WorkFlag.bColseWork; WorkFlag.bAshExit = 1;}
else
{
if(WorkFlag.bColseWork == 0)
{
switch(bKeyVal)
{
case PLAYASH_KEYB: bCurPlayIdx = 0x55;break;
case SAVE_KEYC:
if(WorkFlag.bPlayAshOld == 1)
{
WorkFlag.bAshExit = 1; WorkFlag.bSaveKeyC = 1;WorkFlag.bPlayAshOld = 0;
wCurRedAshVal=wCurRedAsh;wCurGreAshVal=wCurGreAsh; wCurBluAshVal=wCurBluAsh;
}break;
case LOAD_KEYD:
{
bCurPlayIdx++;
if(bCurPlayIdx == 5)bCurPlayIdx = 0;
}break;
default: break;
}
}
WorkFlag.bKeyUpt = 1;
}
SaveWorkState();
}
/*=====================================================================
【功 能】: 保存工作状态
【名 称】: SaveWorkState()
【日 期】: 2006年8月30日
=====================================================================*/
void SaveWorkState(void)
{
eeprom_busy_wait();
eeprom_write_byte (&bLastPlayIdx, bCurPlayIdx);
if(WorkFlag.bSaveKeyC == 1)
{
BYTE bi;
WORD wAshval_Red, wAshval_Gre,wAshval_Blu;
WorkFlag.bSaveKeyC = 0;
bCurPlayIdx = 0;
eeprom_busy_wait();
eeprom_write_byte (&bLastPlayIdx, bCurPlayIdx);
for(bi=4; bi>0; bi--)
{
eeprom_busy_wait();
wAshval_Red = eeprom_read_word(&bColorAsh[bi-1][0]);
eeprom_busy_wait();
wAshval_Gre = eeprom_read_word(&bColorAsh[bi-1][1]);
eeprom_busy_wait();
wAshval_Blu = eeprom_read_word(&bColorAsh[bi-1][2]);
eeprom_busy_wait();
eeprom_write_word (&bColorAsh[bi][0], wAshval_Red);
eeprom_busy_wait();
eeprom_write_word (&bColorAsh[bi][1], wAshval_Gre);
eeprom_busy_wait();
eeprom_write_word (&bColorAsh[bi][2], wAshval_Blu);
}
eeprom_busy_wait();
eeprom_write_word (&bColorAsh[0][0], wCurRedAshVal);
eeprom_busy_wait();
eeprom_write_word (&bColorAsh[0][1], wCurGreAshVal);
eeprom_busy_wait();
eeprom_write_word (&bColorAsh[0][2], wCurBluAshVal);
}
}
/*=====================================================================
【功 能】: 调入工作状态
【名 称】: LoadWorkState()
【日 期】: 2006年8月30日
=====================================================================*/
void LoadWorkState(void)
{
if(WorkFlag.bKeyUpt == 1)
{
eeprom_busy_wait();
bCurPlayIdx = eeprom_read_byte(&bLastPlayIdx);
eeprom_busy_wait();
wCurRedAshVal = eeprom_read_word(&bColorAsh[bCurPlayIdx][0]);
eeprom_busy_wait();
wCurGreAshVal = eeprom_read_word(&bColorAsh[bCurPlayIdx][1]);
eeprom_busy_wait();
wCurBluAshVal = eeprom_read_word(&bColorAsh[bCurPlayIdx][2]);
WorkFlag.bKeyUpt = 0;
}
if(WorkFlag.bColseWork == 1)
{
OFF_Red(); OFF_Gre(); OFF_Blu();
}
else
{
if(bCurPlayIdx == 0x55)
Play_Gradual(PLAY_GRADSPEED);
else
PlayStaticAsh(wCurRedAshVal, wCurGreAshVal, wCurBluAshVal);
}
}
/*=====================================================================
【功 能】: 初始化工作状态
【名 称】: InitWorkState()
【日 期】: 2006年8月30日
=====================================================================*/
void InitWorkState(void)
{
DDRD |= (_BV(PD5) | _BV(PD6) | _BV(PD7));
DDRC &= ~(_BV(PC0) | _BV(PC1) | _BV(PC2) | _BV(PC3));
DDRD &= ~(_BV(PD2));
PORTD |= _BV(PD2);
WorkFlag.bKeyUpt = 1;
WorkFlag.bColseWork = 0;
LoadWorkState();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -