Browse Source

1.1

main v1.1.0
leaf 3 years ago
parent
commit
0e4230b984
  1. 16
      Listings/main.lst
  2. 18
      Listings/snake.m51
  3. 111
      Main/main.c
  4. BIN
      Objects/snake
  5. 2
      Objects/snake.build_log.htm
  6. 24
      snake.uvgui.Simular

16
Listings/main.lst

@ -1,4 +1,4 @@
C51 COMPILER V9.57.0.0 MAIN 06/14/2022 09:14:54 PAGE 1 C51 COMPILER V9.57.0.0 MAIN 06/14/2022 09:51:18 PAGE 1
C51 COMPILER V9.57.0.0, COMPILATION OF MODULE MAIN C51 COMPILER V9.57.0.0, COMPILATION OF MODULE MAIN
@ -62,7 +62,7 @@ line level source
52 1 } 52 1 }
53 53
54 void del(u8 x, u8 y) 54 void del(u8 x, u8 y)
C51 COMPILER V9.57.0.0 MAIN 06/14/2022 09:14:54 PAGE 2 C51 COMPILER V9.57.0.0 MAIN 06/14/2022 09:51:18 PAGE 2
55 { 55 {
56 1 u8 one = 0x01; 56 1 u8 one = 0x01;
@ -126,7 +126,7 @@ line level source
114 1 { 114 1 {
115 2 turn = 1; 115 2 turn = 1;
116 2 } 116 2 }
C51 COMPILER V9.57.0.0 MAIN 06/14/2022 09:14:54 PAGE 3 C51 COMPILER V9.57.0.0 MAIN 06/14/2022 09:51:18 PAGE 3
117 1 else if(key==KEY2_PRESS) 117 1 else if(key==KEY2_PRESS)
118 1 { 118 1 {
@ -190,7 +190,7 @@ line level source
176 { 176 {
177 1 u8 i=0; 177 1 u8 i=0;
178 1 timer0_init(0x01,0x4c,0x00); 178 1 timer0_init(0x01,0x4c,0x00);
C51 COMPILER V9.57.0.0 MAIN 06/14/2022 09:14:54 PAGE 4 C51 COMPILER V9.57.0.0 MAIN 06/14/2022 09:51:18 PAGE 4
179 1 push(head_x,head_y); 179 1 push(head_x,head_y);
180 1 rand_apple(); 180 1 rand_apple();
@ -222,9 +222,9 @@ line level source
206 4 if(head_x == apple_x && head_y == apple_y) 206 4 if(head_x == apple_x && head_y == apple_y)
207 4 { 207 4 {
208 5 del(apple_x,apple_y); 208 5 del(apple_x,apple_y);
209 5 rand_apple(); 209 5 push(head_x,head_y);
210 5 display(apple_x,apple_y); 210 5 rand_apple();
211 5 push(head_x,head_y); 211 5 display(apple_x,apple_y);
212 5 } 212 5 }
213 4 else 213 4 else
214 4 { 214 4 {
@ -254,7 +254,7 @@ MODULE INFORMATION: STATIC OVERLAYABLE
PDATA SIZE = ---- ---- PDATA SIZE = ---- ----
DATA SIZE = ---- ---- DATA SIZE = ---- ----
IDATA SIZE = ---- ---- IDATA SIZE = ---- ----
C51 COMPILER V9.57.0.0 MAIN 06/14/2022 09:14:54 PAGE 5 C51 COMPILER V9.57.0.0 MAIN 06/14/2022 09:51:18 PAGE 5
BIT SIZE = ---- ---- BIT SIZE = ---- ----
END OF MODULE INFORMATION. END OF MODULE INFORMATION.

18
Listings/snake.m51

@ -1,4 +1,4 @@
BL51 BANKED LINKER/LOCATER V6.22.2.0 06/14/2022 09:14:54 PAGE 1 BL51 BANKED LINKER/LOCATER V6.22.2.0 06/14/2022 09:51:18 PAGE 1
BL51 BANKED LINKER/LOCATER V6.22.2.0, INVOKED BY: BL51 BANKED LINKER/LOCATER V6.22.2.0, INVOKED BY:
@ -59,7 +59,7 @@ LINK MAP OF MODULE: .\Objects\snake (MAIN)
OVERLAY MAP OF MODULE: .\Objects\snake (MAIN) OVERLAY MAP OF MODULE: .\Objects\snake (MAIN)
BL51 BANKED LINKER/LOCATER V6.22.2.0 06/14/2022 09:14:54 PAGE 2 BL51 BANKED LINKER/LOCATER V6.22.2.0 06/14/2022 09:51:18 PAGE 2
@ -119,7 +119,7 @@ SYMBOL TABLE OF MODULE: .\Objects\snake (MAIN)
X:0001H PUBLIC queue_x X:0001H PUBLIC queue_x
B:00B0H.6 PUBLIC SRCLK B:00B0H.6 PUBLIC SRCLK
X:0042H PUBLIC queue_y X:0042H PUBLIC queue_y
BL51 BANKED LINKER/LOCATER V6.22.2.0 06/14/2022 09:14:54 PAGE 3 BL51 BANKED LINKER/LOCATER V6.22.2.0 06/14/2022 09:51:18 PAGE 3
D:00B0H PUBLIC P3 D:00B0H PUBLIC P3
@ -179,7 +179,7 @@ SYMBOL TABLE OF MODULE: .\Objects\snake (MAIN)
------- ENDPROC L?0086 ------- ENDPROC L?0086
C:0587H SYMBOL L?0087 C:0587H SYMBOL L?0087
------- PROC _DELAY_10US ------- PROC _DELAY_10US
BL51 BANKED LINKER/LOCATER V6.22.2.0 06/14/2022 09:14:54 PAGE 4 BL51 BANKED LINKER/LOCATER V6.22.2.0 06/14/2022 09:51:18 PAGE 4
D:0006H SYMBOL ten_us D:0006H SYMBOL ten_us
@ -239,7 +239,7 @@ SYMBOL TABLE OF MODULE: .\Objects\snake (MAIN)
C:0562H LINE# 15 C:0562H LINE# 15
C:0566H LINE# 16 C:0566H LINE# 16
C:0568H LINE# 17 C:0568H LINE# 17
BL51 BANKED LINKER/LOCATER V6.22.2.0 06/14/2022 09:14:54 PAGE 5 BL51 BANKED LINKER/LOCATER V6.22.2.0 06/14/2022 09:51:18 PAGE 5
C:056AH LINE# 18 C:056AH LINE# 18
@ -299,7 +299,7 @@ SYMBOL TABLE OF MODULE: .\Objects\snake (MAIN)
------- ENDDO ------- ENDDO
C:04CFH LINE# 54 C:04CFH LINE# 54
C:04CFH LINE# 55 C:04CFH LINE# 55
BL51 BANKED LINKER/LOCATER V6.22.2.0 06/14/2022 09:14:54 PAGE 6 BL51 BANKED LINKER/LOCATER V6.22.2.0 06/14/2022 09:51:18 PAGE 6
C:04CFH LINE# 56 C:04CFH LINE# 56
@ -359,7 +359,7 @@ SYMBOL TABLE OF MODULE: .\Objects\snake (MAIN)
------- PROC _SHOW ------- PROC _SHOW
X:00B2H SYMBOL gled_row X:00B2H SYMBOL gled_row
------- DO ------- DO
BL51 BANKED LINKER/LOCATER V6.22.2.0 06/14/2022 09:14:54 PAGE 7 BL51 BANKED LINKER/LOCATER V6.22.2.0 06/14/2022 09:51:18 PAGE 7
X:00B5H SYMBOL i X:00B5H SYMBOL i
@ -419,7 +419,7 @@ SYMBOL TABLE OF MODULE: .\Objects\snake (MAIN)
------- ENDDO ------- ENDDO
C:0144H LINE# 142 C:0144H LINE# 142
C:0144H LINE# 143 C:0144H LINE# 143
BL51 BANKED LINKER/LOCATER V6.22.2.0 06/14/2022 09:14:54 PAGE 8 BL51 BANKED LINKER/LOCATER V6.22.2.0 06/14/2022 09:51:18 PAGE 8
C:0144H LINE# 145 C:0144H LINE# 145
@ -479,7 +479,7 @@ SYMBOL TABLE OF MODULE: .\Objects\snake (MAIN)
C:00A9H LINE# 197 C:00A9H LINE# 197
C:00B9H LINE# 198 C:00B9H LINE# 198
C:00E0H LINE# 199 C:00E0H LINE# 199
BL51 BANKED LINKER/LOCATER V6.22.2.0 06/14/2022 09:14:54 PAGE 9 BL51 BANKED LINKER/LOCATER V6.22.2.0 06/14/2022 09:51:18 PAGE 9
C:00E0H LINE# 200 C:00E0H LINE# 200

111
Main/main.c

@ -7,7 +7,8 @@
sbit SRCLK=P3^6; //移位寄存器时钟输入 sbit SRCLK=P3^6; //移位寄存器时钟输入
sbit RCLK=P3^5; //存储寄存器时钟输入 sbit RCLK=P3^5; //存储寄存器时钟输入
sbit SER=P3^4; //串行数据输入 sbit SER=P3^4; //串行数据输入
sbit BEEP=P1^5; //音乐
sbit led = P2^0;
#define LEDDZ_COL_PORT P0 //点阵列控制端口 #define LEDDZ_COL_PORT P0 //点阵列控制端口
u8 death[8]={0x00,0x38,0x6e,0x7c,0x7c,0x6e,0x38,0x00}; u8 death[8]={0x00,0x38,0x6e,0x7c,0x7c,0x6e,0x38,0x00};
@ -16,48 +17,65 @@ u8 gled_col[8]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};//LED
u8 map[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; u8 map[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
u8 step[4][2] = {{1,0},{0,1},{-1,0},{0,-1}}; u8 step[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
u8 timer_level[3] = {0x4c,0x50,0x60};//难度控制
u8 level = 0;
u8 queue_x[65]; u8 queue_x[65]; //循环队列x坐标
u8 queue_y[65]; u8 queue_y[65]; //循环队列y坐标
u8 leader=0; u8 leader=0; //头指针
u8 tail=0; u8 tail=0; //尾指针
u8 length=0; u8 length=0; //队列长度
u8 act=0; u8 act=0; //是否执行
u8 game_over=0; u8 game_over=0; //游戏是否结束
u8 turn=0; u8 turn=0; //转向方向
u8 direction=0; u8 direction=0; //当前方向
u8 head_x = 3; u8 head_x = 3; //蛇头部节点x轴
u8 head_y = 3; u8 head_y = 3; //蛇头部节点y轴
u8 apple_x=4; u8 apple_x=4; //食物节点x轴
u8 apple_y=4; u8 apple_y=4; //食物节点y轴
u8 timer = 0; u8 timer = 0; //中断次数
u16 sound_long = 0; //声音持续时间
u8 i; u8 i;
u8 j; u8 j;
/******************************************************************************* //music
* : hc595_write_data(u8 dat) u8 music_index = 0;
* : 74HC595写入一个字节的数据 u8 soundtone_end[] = {6,5,4,3,2,1,1,2};
* : dat u16 soundlong_end[] ={1,1,1,1,1,1,2,1};
* : u8 freq_h[7] = {0XFC,0XFC,0XFD,0XFD,0XFD,0XFD,0XFE}; //音调 1 2 3 4 5 6 7
*******************************************************************************/ u8 freq_l[7] = {0X44,0XAC,0X09,0X34,0X82,0XC8,0X06};
u16 freq[7] = {261.6,293.6,329.6,349.2,392,440,493.8};//对应频率
void display(u8 x, u8 y)
void play_init() //初始化
{
TR1 = 0;
music_index = 0;
BEEP = 0;
timer1_reset(0xff,0xff);
}
void play_death() //死亡后执行
{
TR1=1;
}
void display(u8 x, u8 y) //显示某个点
{ {
u8 one = 0x01; u8 one = 0x01;
map[x] = map[x] + (one<<y); map[x] = map[x] + (one<<y);
} }
void del(u8 x, u8 y) void del(u8 x, u8 y) //取消显示某个点
{ {
u8 one = 0x01; u8 one = 0x01;
map[x] = map[x] - (one<<y); map[x] = map[x] - (one<<y);
} }
void push(u8 x, u8 y) void push(u8 x, u8 y) //循环队列:入队列
{ {
leader++; leader++;
length++; length++;
@ -67,7 +85,7 @@ void push(u8 x, u8 y)
display(x,y); display(x,y);
} }
void pop() void pop() //循环队列:出队列
{ {
u8 one = 0x01; u8 one = 0x01;
tail++; tail++;
@ -77,8 +95,7 @@ void pop()
} }
void hc595_write_data(u8 dat) //数据写一排
void hc595_write_data(u8 dat)
{ {
u8 i=0; u8 i=0;
for(i=0;i<8;i++)//循环8次即可将一个字节写入寄存器中 for(i=0;i<8;i++)//循环8次即可将一个字节写入寄存器中
@ -95,7 +112,7 @@ void hc595_write_data(u8 dat)
RCLK=1;//存储寄存器时钟上升沿将前面写入到寄存器的数据输出 RCLK=1;//存储寄存器时钟上升沿将前面写入到寄存器的数据输出
} }
void show(u8 gled_row[8]) void show(u8 gled_row[8]) //点阵显示
{ {
u8 i=0; u8 i=0;
for(i=0;i<8;i++)//循环8次扫描8行、列 for(i=0;i<8;i++)//循环8次扫描8行、列
@ -107,7 +124,7 @@ void show(u8 gled_row[8])
} }
} }
void monitor_key() void monitor_key() //监控按键
{ {
u8 key=key_scan(0); u8 key=key_scan(0);
if(key==KEY1_PRESS) if(key==KEY1_PRESS)
@ -120,17 +137,16 @@ void monitor_key()
} }
else if(key==KEY3_PRESS) else if(key==KEY3_PRESS)
{ {
level = (level+1)%2;
} }
else if(key==KEY4_PRESS)
{
}
} }
void timer0() interrupt 1 void timer0() interrupt 1 //定时器0 控制每一步时间间隔
{ {
timer0_reset(0x4c,0x00); led = 0;
//timer0_reset(0x4c,0x00);
timer0_reset(timer_level[level],0x00);
timer++; timer++;
if(timer==15) if(timer==15)
{ {
@ -138,8 +154,20 @@ void timer0() interrupt 1
act=1; act=1;
} }
} }
void timer1() interrupt 3 //定时器1 控制音乐播放速度
{
BEEP = !BEEP;
sound_long++;
timer1_reset(freq_h[soundtone_end[music_index]-1],freq_l[soundtone_end[music_index]-1]);
if(sound_long > soundlong_end[music_index] * freq[music_index])
{
music_index++;
sound_long = 0;
}
if(music_index==6){TR1 = 0;}
}
void rand_apple() void rand_apple() //随机生成食物(包括避免生成在自己身上)
{ {
u8 k; u8 k;
u8 rand=TL0%(64-length); u8 rand=TL0%(64-length);
@ -158,7 +186,7 @@ void rand_apple()
over = 1; over = 1;
} }
} }
if(over == 0)// over == 0 but not run rightly if(over == 0)
{ {
if(count == rand) if(count == rand)
{ {
@ -175,14 +203,17 @@ void rand_apple()
void main() void main()
{ {
u8 i=0; u8 i=0;
timer0_init(0x01,0x4c,0x00); timer_init();
play_init();
push(head_x,head_y); push(head_x,head_y);
rand_apple(); rand_apple();
display(apple_x, apple_y); display(apple_x, apple_y);
while(1) while(1)
{ {
monitor_key(); monitor_key();
if(act && game_over == 0){ if(act && game_over == 0){
direction += turn; direction += turn;
direction %= 4; direction %= 4;
head_x += step[direction][0]; head_x += step[direction][0];
@ -219,9 +250,11 @@ void main()
turn = 0; turn = 0;
act = 0; act = 0;
} }
if(game_over) if(game_over)
{ {
show(death); show(death);
play_death();
} }
else else
{ {

BIN
Objects/snake

Binary file not shown.

2
Objects/snake.build_log.htm

@ -37,7 +37,7 @@ linking...
Program Size: data=9.0 xdata=182 code=1436 Program Size: data=9.0 xdata=182 code=1436
creating hex file from ".\Objects\snake"... creating hex file from ".\Objects\snake"...
".\Objects\snake" - 0 Error(s), 3 Warning(s). ".\Objects\snake" - 0 Error(s), 3 Warning(s).
Build Time Elapsed: 00:00:01 Build Time Elapsed: 00:00:00
</pre> </pre>
</body> </body>
</html> </html>

24
snake.uvgui.Simular

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save