Compare commits
2 Commits
Author | SHA1 | Date |
---|---|---|
kirbylife | 24daab9c17 | |
kirbylife | 76102d28a4 |
20
src/main.rs
20
src/main.rs
|
@ -5,19 +5,33 @@
|
|||
use core::arch::asm;
|
||||
use core::ptr::{read_volatile, write_volatile};
|
||||
|
||||
/*
|
||||
PORTC{0..5} Analog
|
||||
PORTC6 Reset
|
||||
|
||||
PORTB{0..5} Digital {8..13}
|
||||
PORTD{0..7} Digital {0..7}
|
||||
|
||||
PORTB5 LED_BUILTIN
|
||||
*/
|
||||
|
||||
const DDRB: *mut u8 = 0x24 as *mut u8;
|
||||
const PORTB: *mut u8 = 0x25 as *mut u8;
|
||||
|
||||
// ATmega328p cycle speed
|
||||
const CPU_SPEED: u32 = 16_000_000;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn main() -> ! {
|
||||
// Set all the B pins on OUTPUT mode
|
||||
unsafe { write_volatile(DDRB, 0b11111111) };
|
||||
|
||||
loop {
|
||||
unsafe { write_volatile(PORTB, 0b00000000) };
|
||||
sleep(1);
|
||||
unsafe { write_volatile(PORTB, 0b00100000) };
|
||||
// if pin[5] == 1: 1^1 = 0
|
||||
// if pin[5] == 0: 0^1 = 1
|
||||
let mut portb_value = unsafe { read_volatile(PORTB) };
|
||||
portb_value = portb_value ^ (1 << 5);
|
||||
unsafe { write_volatile(PORTB, portb_value) };
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue