Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define RCC_AHBENR (*(unsigned int *)(0x40021000 + 0x14))
- #define GPIOB_MODER (*(unsigned int *)(0x48000400 + 0x00))
- #define GPIOB_ODR (*(unsigned int *)(0x48000400 + 0x14))
- #define RCC_APB1ENR (*(unsigned int *)(0x40021000 + 0x1C))
- #define PWR_CR (*(unsigned int *)(0x40007000 + 0x00))
- #define RCC_BDCR (*(unsigned int *)(0x40021000 + 0x20))
- #define RTC_WPR (*(unsigned int *)(0x40002800 + 0x24))
- #define RTC_ISR (*(unsigned int *)(0x40002800 + 0x0C))
- #define RTC_DR (*(unsigned int *)(0x40002800 + 0x04))
- #define RTC_TR (*(unsigned int *)(0x40002800 + 0x00))
- #define GPIOA_PUPDR (*(unsigned int *)(0x48000000 + 0x0C))
- #define GPIOA_IDR (*(unsigned int *)(0x48000000 + 0x10))
- #define GPIOA_ODR (*(unsigned int *)(0x48000000 + 0x14))
- #define GPIOA_MODER (*(unsigned int *)(0x48000000 + 0x00))
- int test = 0;
- int token = 0;
- int counter = 0;
- int i;
- void clockSetup() {
- RCC_APB1ENR = (1 << 28);
- PWR_CR = (1 << 8);
- RCC_BDCR = 0x8101;
- RTC_WPR = 0xCA;
- RTC_WPR = 0x53;
- RTC_ISR = (1 << 7);
- while ((RTC_ISR & 0x40) == 0) {
- asm("nop");
- }
- RTC_DR = 0x0;
- RTC_TR = 0x0;
- RTC_ISR &= (0 << 7);
- RTC_WPR = 0xFE;
- RTC_WPR = 0x64;
- PWR_CR &= (0 << 8);
- }
- void boardSetup() {
- RCC_AHBENR |= (1 << 17);
- GPIOA_PUPDR |= 0x4;
- GPIOA_MODER |= 0x400;
- GPIOA_MODER |= 0x4000;
- }
- void clock(int pulse) {
- for (int k = 0; k < pulse; k++) {
- GPIOA_ODR |= 0x20;
- GPIOA_ODR &= ~0x20;
- }
- }
- void begin() {
- GPIOA_ODR |= 0x00A0;
- }
- void start() {
- GPIOA_ODR &= ~0x80;
- GPIOA_ODR &= ~0x20;
- }
- void stop() {
- GPIOA_ODR |= 0x20;
- GPIOA_ODR |= 0x80;
- }
- void acknowledge() {
- clock(1);
- }
- void zero() {
- GPIOA_ODR |= 0x80;
- clock(6);
- GPIOA_ODR &= ~0x80;
- clock(1);
- GPIOA_ODR |= 0x80;
- clock(1);
- GPIOA_ODR &= ~0x80;
- acknowledge();
- }
- void one() {
- clock(1);
- GPIOA_ODR |= 0x80;
- clock(2);
- GPIOA_ODR &= ~0x80;
- clock(4);
- GPIOA_ODR |= 0x80;
- clock(1);
- GPIOA_ODR &= ~0x80;
- acknowledge();
- }
- void two() {
- GPIOA_ODR |= 0x80;
- clock(2);
- GPIOA_ODR &= ~0x80;
- clock(1);
- GPIOA_ODR |= 0x80;
- clock(2);
- GPIOA_ODR &= ~0x80;
- clock(1);
- GPIOA_ODR |= 0x80;
- clock(2);
- GPIOA_ODR &= ~0x80;
- acknowledge();
- }
- void three() {
- GPIOA_ODR |= 0x80;
- clock(4);
- GPIOA_ODR &= ~0x80;
- clock(2);
- GPIOA_ODR |= 0x80;
- clock(2);
- GPIOA_ODR &= ~0x80;
- acknowledge();
- }
- void four() {
- clock(1);
- GPIOA_ODR |= 0x80;
- clock(2);
- GPIOA_ODR &= ~0x80;
- clock(2);
- GPIOA_ODR |= 0x80;
- clock(3);
- GPIOA_ODR &= ~0x80;
- acknowledge();
- }
- void five() {
- GPIOA_ODR |= 0x80;
- clock(1);
- GPIOA_ODR &= ~0x80;
- clock(1);
- GPIOA_ODR |= 0x80;
- clock(2);
- GPIOA_ODR &= ~0x80;
- clock(1);
- GPIOA_ODR |= 0x80;
- clock(3);
- GPIOA_ODR &= ~0x80;
- acknowledge();
- }
- void six() {
- GPIOA_ODR |= 0x80;
- clock(1);
- GPIOA_ODR &= ~0x80;
- clock(1);
- GPIOA_ODR |= 0x80;
- clock(6);
- GPIOA_ODR &= ~0x80;
- acknowledge();
- }
- void seven() {
- GPIOA_ODR |= 0x80;
- clock(3);
- GPIOA_ODR &= ~0x80;
- clock(4);
- GPIOA_ODR |= 0x80;
- clock(1);
- GPIOA_ODR &= ~0x80;
- acknowledge();
- }
- void eight() {
- GPIOA_ODR |= 0x80;
- clock(8);
- GPIOA_ODR &= ~0x80;
- acknowledge();
- }
- void nine() {
- GPIOA_ODR |= 0x80;
- clock(4);
- GPIOA_ODR &= ~0x80;
- clock(1);
- GPIOA_ODR |= 0x80;
- clock(3);
- GPIOA_ODR &= ~0x80;
- acknowledge();
- }
- void dataCommand() {
- start();
- clock(6);
- GPIOA_ODR |= 0x80;
- clock(1);
- GPIOA_ODR &= ~0x80;
- clock(1);
- acknowledge();
- stop();
- }
- void displayControllCommand() {
- start();
- clock(2);
- GPIOA_ODR |= 0x0080;
- clock(2);
- GPIOA_ODR &= ~0x0080;
- clock(3);
- GPIOA_ODR |= 0x0080;
- clock(1);
- GPIOA_ODR &= ~0x0080;
- acknowledge();
- stop();
- }
- void addressCommand() {
- start();
- clock(6);
- GPIOA_ODR |= 0x80;
- clock(2);
- GPIOA_ODR &= ~0x0080;
- acknowledge();
- }
- void display(int sec) {
- addressCommand();
- switch (sec) {
- case 0:
- zero();
- break;
- case 1:
- one();
- break;
- case 2:
- two();
- break;
- case 3:
- three();
- break;
- case 4:
- four();
- break;
- case 5:
- five();
- break;
- case 6:
- six();
- break;
- case 7:
- seven();
- break;
- case 8:
- eight();
- break;
- case 9:
- nine();
- break;
- }
- stop();
- }
- int timerDelay(int sec) {
- if ((RTC_TR & 0x1) == 0) {
- if (test == 0) {
- sec++;
- test++;
- }
- }
- if ((RTC_TR & 0x1) == 1) {
- if (test == 1) {
- sec++;
- test--;
- }
- }
- return sec;
- }
- void reset(int sec) {
- sec = 0;
- display(sec);
- }
- int main() {
- int sec = 0;
- boardSetup();
- begin();
- dataCommand();
- displayControllCommand();
- clockSetup();
- reset(sec);
- token = ~token;
- while (1) {
- display(sec % 10);
- display(sec / 10 % 6);
- display(sec / 60 % 10);
- display(sec / 600 % 10);
- sec = timerDelay(sec);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement