#define _STYLES_C_
#include <stc15.h>
#include "Driver_595.h"
#include "Styles.h"
#define Random(x) (rand() % x) //通过取余取得指定范围的随机数
int rand();
//打开所有灯
unsigned char Style_AllLightOn(void)
{
unsigned char pos_current_x = 0;
unsigned char pos_current_y = 0;
unsigned char pos_current_z = 0;
for ( pos_current_z = 0 ; pos_current_z < LIGHT_CUBE_SIZE ; pos_current_z++ )
for ( pos_current_y = 0 ; pos_current_y < LIGHT_CUBE_SIZE ; pos_current_y++ )
for ( pos_current_x = 0 ; pos_current_x < LIGHT_CUBE_SIZE ; pos_current_x++ )
Display_Buffer[pos_current_z][pos_current_y][pos_current_x] = 0xFF;
return 0;
}
//关闭所有灯
unsigned char Style_AllLightOff(void)
{
unsigned char pos_current_x = 0;
unsigned char pos_current_y = 0;
unsigned char pos_current_z = 0;
for ( pos_current_z = 0 ; pos_current_z < LIGHT_CUBE_SIZE ; pos_current_z++ )
for ( pos_current_y = 0 ; pos_current_y < LIGHT_CUBE_SIZE ; pos_current_y++ )
for ( pos_current_x = 0 ; pos_current_x < LIGHT_CUBE_SIZE ; pos_current_x++ )
Display_Buffer[pos_current_z][pos_current_y][pos_current_x] = 0x00;
return 0;
}
//所有灯全亮全灭闪断
//cnt 次数
//return 灯亮返回1, 灯灭返回0.
unsigned char Style_AllFlush(unsigned char cnt)
{
//速度设置
const unsigned int speed = 50;
static unsigned int t_cnt = 0;
//标志指示器.
static unsigned char flag_light_on = 0;
//闪烁计数
static unsigned char flush_cnt = 0;
t_cnt++;
if (t_cnt >= speed)
{
t_cnt = 0;
flag_light_on = ~flag_light_on;
if (flag_light_on) {Style_AllLightOn();}
else {flush_cnt++; Style_AllLightOff();}
}
if (flush_cnt < cnt) {return 0;}
else {flush_cnt = 0; return 1;}
}
//Scan all 512 lights. Set every light on. Then reverse.
//reset 重置函数内静态变量.
unsigned char Style_ScanEachLight(unsigned char reset)
{
//速度设置
const unsigned int speed = 1;
static unsigned int t_cnt = 0;
static unsigned char *pos = Display_Buffer;
static signed char direction = 0; //方向
static signed int offset_begin = 0; //灯条头位置
static signed int offset_end = 0; //灯条尾位置
static signed int light_len = 3; //灯条长度
//计数
static unsigned int flush_cnt = 0;
if (reset)
{
Style_AllLightOff();
direction = 0;
offset_begin = 0;
offset_end = 0;
}
t_cnt++;
if (t_cnt >= speed)
{
t_cnt = 0;
flush_cnt++;
if (direction == 0)
{
offset_end = offset_begin - light_len;
offset_end = offset_end < 0 ? 0 : offset_end;
}
else
{
offset_end = offset_begin + light_len;
offset_end = offset_end > DISPLAY_BUFFER_SIZE ? (DISPLAY_BUFFER_SIZE - 1) : offset_end;
}
*(pos + offset_begin) = 0xFF;
*(pos + offset_end) = 0x00;
if (direction == 0){offset_begin++;}
else{offset_begin--;}
if (offset_begin >= DISPLAY_BUFFER_SIZE)
{offset_begin = DISPLAY_BUFFER_SIZE - 2; direction=~direction;}
if (offset_begin <= -1)
{offset_begin = 1; direction=~direction;}
}
if (flush_cnt < 1024){return 0;}
else {flush_cnt = 0; return 1;}
}
//依次扫描所有512个灯, 所有灯亮, 再所有灯灭.
//reset 重置函数内静态变量.
unsigned char Style_ScanEachLight_1(unsigned char reset)
{
//速度设置
const unsigned int speed = 1;
static unsigned int t_cnt = 0;
unsigned char *pos = Display_Buffer;
static unsigned char flag = 0; //方向
static unsigned int offset = 0;
//计数
static unsigned int flush_cnt = 0;
if (reset)
{
Style_AllLightOff();
t_cnt = 0;
flag = 0;
offset = 0;
flush_cnt = 0;
}
t_cnt++;
if (t_cnt >= speed)
{
t_cnt = 0;
flush_cnt++;
if (flag == 0)
*(pos + offset) = 0xFF;
else
*(pos + offset) = 0x00;
offset++;
if (offset >= DISPLAY_BUFFER_SIZE){offset = 0; flag=~flag;}
}
if (flush_cnt < 1024){return 0;}
else {flush_cnt = 0; return 1;}
}
//以下是各种效果代码, 注意每个方法是一个效果执行一次, 想要循环需要反复调用.
//reset 重置函数内静态变量.
//阶梯型上升
unsigned char Style_N1(unsigned char reset)
{
//速度设置
const unsigned int speed = 5;
static unsigned int t_cnt = 0;
unsigned char pos_current_x = 0;
unsigned char pos_current_y = 0;
unsigned char pos_current_z = 0;
static unsigned int selected_position = 0;
//计数
static unsigned int flush_cnt = 0;
if (reset)
{
Style_AllLightOff();
t_cnt = 0;
selected_position = 0;
}
t_cnt++;
if (t_cnt >= speed)
{
t_cnt = 0;
flush_cnt++;
for ( pos_current_z = 0 ; pos_current_z < LIGHT_CUBE_SIZE ; pos_current_z++ )
for ( pos_current_y = 0 ; pos_current_y < LIGHT_CUBE_SIZE ; pos_current_y++ )
for ( pos_current_x = 0 ; pos_current_x < LIGHT_CUBE_SIZE ; pos_current_x++ )
if ( pos_current_y == selected_position && pos_current_z == selected_position)
Display_Buffer[pos_current_z][pos_current_y][pos_current_x] = 0xFF;
else
Display_Buffer[pos_current_z][pos_current_y][pos_current_x] = 0x00;
selected_position++;
if ( selected_position >= 8 ) selected_position = 0;
}
if (flush_cnt < 8){return 0;}
else {flush_cnt = 0; return 1;}
}
//沿某轴方向上进行单层滚动
//load_datas 指示是否加载数据, 0-使用现有数据, 1-加载新数据.
//axis 要移动的目标轴,
//direction 方向, 0时沿轴线正方向移动, 1时沿轴线负方向移动.
//layer_datas_buffer 要显示出来的数据, 单层数据量为 8*8 64.
unsigned char Style_RollLayer(unsigned char load_datas, enum AxisDirection axis, unsigned char direction, unsigned char* layer_datas_buffer)
{
//速度设置
const unsigned int speed = 5;
static unsigned int t_cnt = 0;
signed char pos_offset = 0;
signed char pos_current_x = 0;
signed char pos_current_y = 0;
signed char pos_current_z = 0;
static signed int layer_cnt = 0;
static signed char layer_position = 0;
signed char pre_position = 0;
const int layer_datas_buffer_len = LIGHT_CUBE_SIZE * LIGHT_CUBE_SIZE;
if (load_datas)
{
Style_AllLightOff();
t_cnt = 0;
layer_cnt = 0;
layer_position = 0;
//装载原始数据.
switch( axis )
{
case X:
{
pos_current_x = 0;
for ( pos_current_z = LIGHT_CUBE_SIZE - 1 ; pos_current_z >= 0 ; pos_current_z-- )
for ( pos_current_y = LIGHT_CUBE_SIZE - 1 ; pos_current_y >= 0 ; pos_current_y-- )
{
Display_Buffer[pos_current_z][pos_current_y][pos_current_x] = *(layer_datas_buffer + pos_offset);
pos_offset++;
}
break;
}
case Y:
{
pos_current_y = 0;
for ( pos_current_z = LIGHT_CUBE_SIZE - 1 ; pos_current_z >= 0 ; pos_current_z-- )
for ( pos_current_x = 0 ; pos_current_x < LIGHT_CUBE_SIZE ; pos_current_x++ )
{
Display_Buffer[pos_current_z][pos_current_y][pos_current_x] = *(layer_datas_buffer + pos_offset);
pos_offset++;
}
break;
}
case Z:
{
pos_current_z = 0;
for ( pos_current_y = LIGHT_CUBE_SIZE - 1 ; pos_current_y >= 0 ; pos_current_y-- )
for ( pos_current_x = 0 ; pos_current_x < LIGHT_CUBE_SIZE ; pos_current_x++ )
{
Display_Buffer[pos_current_z][pos_current_y][pos_current_x] = *(layer_datas_buffer + pos_offset);
pos_offset++;
}
break;
}
default:
{
}
}
return 0;
}
t_cnt++;
if (t_cnt >= speed)
{
t_cnt = 0;
layer_cnt++;
if(direction) { layer_position++; layer_position = layer_position < LIGHT_CUBE_SIZE ? layer_position : 0; pos_offset = -1; }
else { layer_position--; layer_position = layer_position >= 0 ? layer_position : (LIGHT_CUBE_SIZE - 1); pos_offset = 1;}
switch( axis )
{
case X:
{
pos_current_x = layer_position;
for ( pos_current_z = 0 ; pos_current_z < LIGHT_CUBE_SIZE ; pos_current_z++ )
for ( pos_current_y = 0 ; pos_current_y < LIGHT_CUBE_SIZE ; pos_current_y++ )
{
pre_position = pos_current_x + pos_offset;
if ( pre_position >= LIGHT_CUBE_SIZE ) pre_position = 0;
if ( pre_position < 0 ) pre_position = LIGHT_CUBE_SI
没有合适的资源?快使用搜索试试~ 我知道了~
LightCube888_STC15W_595_光立方_源码
共27个文件
lst:5个
obj:5个
c:3个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 124 浏览量
2021-10-04
00:19:23
上传
评论
收藏 76KB RAR 举报
温馨提示
光立方,可以实现多种灯的闪烁,控制光立方
资源推荐
资源详情
资源评论
收起资源包目录
LightCube888_STC15W_595.rar (27个子文件)
LightCube888_STC15W_595
Driver_573.obj 427B
main.OBJ 6KB
STYLES
styles.c 36KB
styles.h 580B
LightCube888_STC15W_595.build_log.htm 1KB
styles.lst 59KB
LightCube888_STC15W_595.hex 45KB
main.c 1KB
DRIVER_595
Driver_595.c 6KB
Driver_595.h 754B
STARTUP.LST 14KB
main.LST 3KB
LightCube888_STC15W_595.M51 59KB
Driver_573.lst 9KB
Driver_595.obj 9KB
LightCube888_STC15W_595.lnp 109B
LightCube888_STC15W_595.plg 595B
STARTUP.A51 6KB
LightCube888_STC15W_595.uvopt 7KB
LightCube888_STC15W_595.uvproj 15KB
LightCube888_STC15W_595.uvgui.Daisy 176KB
styles.obj 68KB
LightCube888_STC15W_595_uvproj.bak 15KB
LightCube888_STC15W_595 69KB
LightCube888_STC15W_595_uvopt.bak 7KB
STARTUP.OBJ 749B
Driver_595.lst 9KB
共 27 条
- 1
资源评论
慕酒
- 粉丝: 48
- 资源: 4823
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功