再加功能
This commit is contained in:
parent
4aae506847
commit
094ec9498a
4 changed files with 62 additions and 26 deletions
|
@ -12,8 +12,14 @@ sbit E = P3 ^ 2;
|
|||
sbit CSA = P3 ^ 4;
|
||||
sbit CSB = P3 ^ 5;
|
||||
|
||||
static unsigned char displayCache[2][8][64];
|
||||
// 2 Screen 8 Page 64 Line
|
||||
|
||||
unsigned char sine[] = {32,33,34,36,37,39,40,42,43,44,46,47,48,49,51,52,53,54,55,56,56,57,58,59,59,60,60,61,61,61,61,61,61,61,61,61,61,61,60,60,59,59,58,57,56,56,55,54,53,52,51,49,48,47,46,44,43,42,40,39,37,36,34,33,32,30,29,27,26,24,23,21,20,19,17,16,15,14,12,11,10,9,8,7,7,6,5,4,4,3,3,2,2,2,2,2,2,2,2,2,2,2,3,3,4,4,5,6,7,7,8,9,10,11,12,14,15,16,17,19,20,21,23,24,26,27,29,30};
|
||||
|
||||
void addDot(unsigned char x, unsigned char y);
|
||||
{
|
||||
displayCache[x / 64][y / 8][x % 64] += 1 << (y % 8);
|
||||
}
|
||||
|
||||
void write()
|
||||
{
|
||||
|
@ -26,43 +32,45 @@ void write()
|
|||
|
||||
void draw()
|
||||
{
|
||||
unsigned int j;
|
||||
unsigned int i, j;
|
||||
CSA = 1;
|
||||
CSB = 0;
|
||||
for(i = 0; i < 8; i++)
|
||||
{
|
||||
RS = 0;
|
||||
RW = 0;
|
||||
P1 = 0xb8 + i;
|
||||
write();
|
||||
P1 = 0X40;
|
||||
write();
|
||||
|
||||
for(j = 0; j < 64; j++)
|
||||
{
|
||||
|
||||
RS = 0;
|
||||
RW = 0;
|
||||
P1 = 0xb8 + (sine[j] / 8); //页
|
||||
write();
|
||||
P1 = 0X40 + j; //Y
|
||||
write();
|
||||
RS = 1;
|
||||
RW = 0;
|
||||
P1 = 1<<(sine[j] % 8);
|
||||
P1 = displayCache[0][i][j];
|
||||
write();
|
||||
}
|
||||
|
||||
}
|
||||
CSA = 0;
|
||||
CSB = 1;
|
||||
for(j = 0; j < 64; j++)
|
||||
for(i = 0; i < 8; i++)
|
||||
{
|
||||
|
||||
RS = 0;
|
||||
RW = 0;
|
||||
P1 = 0xb8 + (sine[63 + j] / 8); //页
|
||||
P1 = 0xb8 + i;
|
||||
write();
|
||||
P1 = 0X40 + j; //Y
|
||||
P1 = 0X40;
|
||||
write();
|
||||
|
||||
|
||||
for(j = 0; j < 64; j++)
|
||||
{
|
||||
RS = 1;
|
||||
RW = 0;
|
||||
P1 = 1<<(sine[j+63] % 8);
|
||||
P1 = displayCache[1][i][j];
|
||||
write();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -108,6 +116,7 @@ void clear()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void init()
|
||||
{
|
||||
E = 0;
|
||||
|
@ -125,6 +134,7 @@ void init()
|
|||
write();
|
||||
}
|
||||
|
||||
|
||||
void test()
|
||||
{
|
||||
unsigned int i, j;
|
||||
|
|
|
@ -14,4 +14,5 @@ void clear();
|
|||
void name(unsigned int i);
|
||||
void write();
|
||||
void draw();
|
||||
void addDot(unsigned char x, unsigned char y);
|
||||
#endif
|
|
@ -2,8 +2,11 @@
|
|||
|
||||
static Body snake[40] = {{0, 0}, 0};
|
||||
static unsigned char len = 0;
|
||||
|
||||
|
||||
void snake_init()
|
||||
{
|
||||
// Initialize snake
|
||||
snake[len].d.x = 63;
|
||||
snake[len].d.y = 31;
|
||||
snake[len].m = R;
|
||||
|
@ -37,21 +40,25 @@ void snake_move()
|
|||
int i = 0;
|
||||
for(; i <= len; i++)
|
||||
{
|
||||
//All body parts move
|
||||
body_move(snake[i]);
|
||||
}
|
||||
for(i = 1; i <= len; i++)
|
||||
{
|
||||
//Sync move direction for next move
|
||||
snake[i].m = snake[i - 1].m;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void body_add()
|
||||
{
|
||||
// Copy last body part to new body part
|
||||
len++
|
||||
snake[len].m = snake[len - 1].m;
|
||||
snake[len].d.x = snake[len - 1].d.x;
|
||||
snake[len].d.x = snake[len - 1].d.x;
|
||||
snake[len].d.y = snake[len - 1].d.y;
|
||||
|
||||
// Judge the direction of new body part
|
||||
switch(snake[len].m)
|
||||
{
|
||||
case R:
|
||||
|
@ -72,11 +79,25 @@ void body_add()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void test()
|
||||
void snake_draw()
|
||||
{
|
||||
int i=1;
|
||||
addDot(nake[0].d.x,nake[0].d.y);
|
||||
addDot(nake[0].d.x+1,nake[0].d.y);
|
||||
addDot(nake[0].d.x,nake[0].d.y+1);
|
||||
addDot(nake[0].d.x-1,nake[0].d.y);
|
||||
addDot(nake[0].d.x,nake[0].d.y-1);
|
||||
|
||||
for(;i<=len;i++)
|
||||
{
|
||||
addDot(nake[i].d.x,nake[i].d.y);
|
||||
}
|
||||
}
|
||||
|
||||
void snake_test()
|
||||
{
|
||||
//Add 14 Body to test
|
||||
int i = 0;
|
||||
for(; i < 15; i++)
|
||||
body_add();
|
||||
|
||||
}
|
|
@ -1,3 +1,6 @@
|
|||
#ifndef _SNAKE_H_
|
||||
#define _SNAKE_H_
|
||||
|
||||
#include <reg52.h>
|
||||
#include <stdio.h>
|
||||
#define bool char
|
||||
|
@ -25,3 +28,4 @@ struct BODY
|
|||
|
||||
typedef struct BODY Body;
|
||||
|
||||
#endif
|
Reference in a new issue