Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bmptk.h"
- #include "pins.h"
- #include "timer.h"
- #include "sw-uart.h"
- void set_ad_converter(int port, int pin){
- // Enable A/D clock
- LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 13);
- // Enable IO config
- LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 16);
- // Configure A/D pin
- LPC_IOCON->R_PIO1_0 &= ~(1 << 7);
- LPC_IOCON->R_PIO1_0 |= 0x02;
- // Enable A/D
- LPC_SYSCON->PDRUNCFG &= ~(1 << 4);
- LPC_ADC->CR |= (1 << 0);
- LPC_ADC->CR |= (2 << 8);
- LPC_ADC->CR |= (0 << 16);
- }
- int read_ad_converter() {
- LPC_ADC->CR |= (1 << 24);
- int value = 0;
- delay(100);
- // Check if the 31 bit of LPC_ADC->GDR is equal to 0
- while((value & (1 << 31)) == 0){
- value = LPC_ADC->GDR;
- }
- uart_put_int_hexadecimal(value, 8);
- value = (value & 0xFFC0) >> 6;
- LPC_ADC->CR &= ~(1 << 24);
- return value;
- }
- int main( void ){
- set_ad_converter(1, 0);
- LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 12);
- LPC_SYSCON->UARTCLKDIV = 0x01;
- timer_init();
- uart_init();
- uart_put_string("A/D conversion results\n");
- while(1) {
- uart_put_string("\n");
- uart_put_int_decimal(read_ad_converter());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement