adc for random number generation not yet working

This commit is contained in:
2024-03-20 21:56:19 +01:00
parent 8c995f66ff
commit 50486f6ec0
5 changed files with 44 additions and 12 deletions

24
game-ctrl/myrand.c Normal file
View 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;
}