partially worked microdrill

This commit is contained in:
eddyem
2019-01-05 19:59:37 +03:00
parent 8c7bd90c39
commit 897a2f1cbf
86 changed files with 42636 additions and 3019 deletions

39
SNIPPETS/eeprom_flash.c Normal file
View File

@@ -0,0 +1,39 @@
/**
* Change variable stored in FLASH
* !!! You can change only const values (non-constants are initializes on program start)
* @param addr - variable address
* @param new value
* @return 0 in case of error
*/
U8 change_progmem_value(U8 *addr, U8 val){
// unlock memory
FLASH_PUKR = EEPROM_KEY2;
FLASH_PUKR = EEPROM_KEY1;
// check bit PUL=1 in FLASH_IAPSR
if(!FLASH_IAPSR & 0x02)
return 0;
*addr = val;
// clear PUL to lock write
FLASH_IAPSR &= ~0x02;
return 1;
}
/**
* Change data in EEPROM
* @param addr - EEPROM address
* @param new value
* @return 0 in case of error
*/
U8 change_eeprom_value(U8 *addr, U8 val){
// unlock eeprom
FLASH_DUKR = EEPROM_KEY1;
FLASH_DUKR = EEPROM_KEY2;
// check bit DUL=1 in FLASH_IAPSR
if(!FLASH_IAPSR & 0x08)
return 0;
*addr = val;
// clear DUL to lock write
FLASH_IAPSR &= ~0x08;
return 1;
}
*/

11
SNIPPETS/uart.c Normal file
View File

@@ -0,0 +1,11 @@
// configure UART
PORT(UART_PORT, DDR) |= UART_TX_PIN; // output
PORT(UART_PORT, ODR) |= UART_TX_PIN; // torn off N push-down
// For open-drain output comment next line
PORT(UART_PORT, CR1) |= UART_TX_PIN; // push-pull
// 9 bit, no parity, 1 stop (UART_CR3 = 0 - reset value)
// 57600 on 16MHz: BRR1=0x11, BRR2=0x06
UART2_BRR1 = 0x11; UART2_BRR2 = 0x06;
// UART2_CR1 = UART_CR1_M; // M = 1 -- 9bits
// for several uarts on line don't write UART_CR2_TEN here, write it when need
UART2_CR2 = UART_CR2_TEN | UART_CR2_REN | UART_CR2_RIEN; // Allow Tx/RX, generate ints on rx

View File

@@ -0,0 +1,4 @@
// macro for using in port constructions like PORT(LED_PORT, ODR) = xx
#define CONCAT(a,b) a##_##b
#define PORT(a,b) CONCAT(a,b)