adc for random number generation not yet working
This commit is contained in:
parent
8c995f66ff
commit
50486f6ec0
@ -7,11 +7,11 @@ MCU=msp430g2553
|
||||
CFLAGS=-Wall -mmcu=$(MCU) -std=gnu99 -I $(TOOLCHAIN_PREFIX)/include -O1 -g0
|
||||
|
||||
# for debugging
|
||||
#CFLAGS+= -g3 -ggdb -gdwarf-2
|
||||
CFLAGS+= -g3 -ggdb -gdwarf-2
|
||||
|
||||
LDFLAGS=-mmcu=$(MCU) -L $(TOOLCHAIN_PREFIX)/include
|
||||
|
||||
$(ARTIFACT).elf: main.o led.o scheduler.o canvas.o shapes.o game.o buttons.o
|
||||
$(ARTIFACT).elf: main.o led.o scheduler.o canvas.o shapes.o game.o buttons.o myrand.o
|
||||
$(CC) -o $@ $(LDFLAGS) $^
|
||||
$(OBJDUMP) -D $(ARTIFACT).elf > $(ARTIFACT).txt
|
||||
|
||||
|
@ -62,6 +62,6 @@ void gameExec(void *handle) {
|
||||
}
|
||||
|
||||
void gameInit() {
|
||||
schAdd(gameExec, NULL, 0, 5000);
|
||||
schAdd(gameExec, NULL, 0, 1000);
|
||||
}
|
||||
|
||||
|
24
game-ctrl/myrand.c
Normal file
24
game-ctrl/myrand.c
Normal file
@ -0,0 +1,24 @@
|
||||
#include <stdint.h>
|
||||
#include <msp430g2553.h>
|
||||
|
||||
#include "myrand.h"
|
||||
|
||||
void myRandInit() {
|
||||
ADC10CTL0 = SREF_1 | ADC10SHT_1 | ADC10SR | REFON | ADC10ON;
|
||||
ADC10CTL1 = INCH_10;
|
||||
}
|
||||
|
||||
uint8_t myRandGet() {
|
||||
ADC10CTL0 |= ENC | ADC10SC;
|
||||
|
||||
while ((ADC10CTL0 & ADC10IFG) == 0);
|
||||
|
||||
uint16_t n = ADC10MEM;
|
||||
uint8_t r = n & 0x00ff;
|
||||
|
||||
ADC10CTL0 &= ~(ADC10IFG | ENC);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
8
game-ctrl/myrand.h
Normal file
8
game-ctrl/myrand.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef _MYRAND_H_
|
||||
#define _MYRAND_H_
|
||||
|
||||
void myRandInit();
|
||||
uint8_t myRandGet();
|
||||
|
||||
|
||||
#endif // _MYRAND_H_
|
@ -1,7 +1,9 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "shapes.h"
|
||||
#include "myrand.h"
|
||||
#include "canvas.h"
|
||||
#include "../rgb-driver/colors.h"
|
||||
|
||||
@ -354,16 +356,14 @@ void shapesInit() {
|
||||
}
|
||||
|
||||
void stoneCreate() {
|
||||
#if 0
|
||||
static uint8_t cnt = 0;
|
||||
// static uint8_t cnt = 0;
|
||||
uint8_t r = myRandGet();
|
||||
uint8_t cnt = r % e_ShapeInvalid;
|
||||
stone.shape = ((shape_t[]){ e_I, e_O, e_T, e_Z, e_S, e_L, e_J })[cnt];
|
||||
cnt++;
|
||||
if (cnt > 3) {
|
||||
cnt = 0;
|
||||
}
|
||||
#else
|
||||
stone.shape = e_J;
|
||||
#endif
|
||||
// cnt++;
|
||||
// if (cnt >= e_ShapeInvalid) {
|
||||
// cnt = 0;
|
||||
// }
|
||||
stone.orientation = e_0;
|
||||
stone.x = 5;
|
||||
stone.y = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user