Compare commits

...

2 Commits

Author SHA1 Message Date
kirbylife 24daab9c17 add comments 2022-12-10 23:48:27 -06:00
kirbylife 76102d28a4 now use the read_volatile and xor op to flip the bit value 2022-12-10 00:45:48 -06:00
1 changed files with 17 additions and 3 deletions

View File

@ -5,19 +5,33 @@
use core::arch::asm; use core::arch::asm;
use core::ptr::{read_volatile, write_volatile}; 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 DDRB: *mut u8 = 0x24 as *mut u8;
const PORTB: *mut u8 = 0x25 as *mut u8; const PORTB: *mut u8 = 0x25 as *mut u8;
// ATmega328p cycle speed
const CPU_SPEED: u32 = 16_000_000; const CPU_SPEED: u32 = 16_000_000;
#[no_mangle] #[no_mangle]
pub extern "C" fn main() -> ! { pub extern "C" fn main() -> ! {
// Set all the B pins on OUTPUT mode
unsafe { write_volatile(DDRB, 0b11111111) }; unsafe { write_volatile(DDRB, 0b11111111) };
loop { loop {
unsafe { write_volatile(PORTB, 0b00000000) }; // if pin[5] == 1: 1^1 = 0
sleep(1); // if pin[5] == 0: 0^1 = 1
unsafe { write_volatile(PORTB, 0b00100000) }; let mut portb_value = unsafe { read_volatile(PORTB) };
portb_value = portb_value ^ (1 << 5);
unsafe { write_volatile(PORTB, portb_value) };
sleep(1); sleep(1);
} }
} }