Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "include/project.h"
- #include "stdio.h"
- #define A 1 << 25
- #define B 1 << 24
- #define C 1 << 22
- #define D 1 << 21
- #define E 1 << 20
- #define F 1 << 27
- #define G 1 << 26
- #define DP 1 << 23
- #define LEFT 1 << 30
- #define RIGHT 1 << 28
- unsigned int number[10];
- void delay() {
- volatile int i;
- i = 6000;
- while(i) {
- i -= 1;
- }
- }
- void screen_left (int numer) {
- AT91C_BASE_PIOB->PIO_SODR = LEFT; //ustawienie lewego screenu
- AT91C_BASE_PIOB->PIO_SODR |= number[numer]; //wyświetlenie numeru - Set Output Data Register
- AT91C_BASE_PIOB->PIO_PER |= number[numer];
- AT91C_BASE_PIOB->PIO_OER |= number[numer];
- delay();
- AT91C_BASE_PIOB->PIO_CODR = number[8];
- AT91C_BASE_PIOB->PIO_CODR = LEFT; // wyczyszczenie data - Clear Output Data Register
- }
- void screen_right (int numer) {
- AT91C_BASE_PIOB->PIO_SODR = RIGHT;
- AT91C_BASE_PIOB->PIO_SODR |= number[numer];
- AT91C_BASE_PIOB->PIO_PER |= number[numer];
- AT91C_BASE_PIOB->PIO_OER |= number[numer];
- delay();
- AT91C_BASE_PIOB->PIO_CODR = number[8];
- AT91C_BASE_PIOB->PIO_CODR = RIGHT;
- }
- void show_number (int left, int right) {
- volatile int i;
- for(i = 0; i < 100; i++) {
- screen_left(left);
- screen_right(right);
- }
- }
- void counter99 () {
- int i, j;
- for(i = 0; i <= 9; i++) {
- for(j = 0; j <= 9; ) {
- show_number(i, j);
- if((*AT91C_PIOC_PDSR & 1<<4) != 0){
- j++;
- }
- else{
- j--;
- if(j==0&&i!=0){
- i--;
- j=9;
- }
- else if(i==0&&j==0){
- i=9;
- j=9;
- }
- }
- }
- }
- }
- void counter9 () {
- int i, j;
- i=0;
- for(j = 0; j <= 9; j++) {
- show_number(i, j);
- }
- }
- void set_number_table (){
- number[0] = A|B|C|D|E|F;
- number[1] = B|C;
- number[2] = A|B|G|E|D;
- number[3] = A|B|G|C|D;
- number[4] = B|F|G|C;
- number[5] = A|F|G|C|D;
- number[6] = A|F|G|C|D|E;
- number[7] = A|B|C;
- number[8] = A|B|C|D|E|F|G;
- number[9] = A|B|G|F|C|D;
- }
- void unlock_ports (){
- AT91C_BASE_PIOB->PIO_PER = LEFT; //PIO Enable Register
- AT91C_BASE_PIOB->PIO_OER = LEFT; //Output Enable Register
- AT91C_BASE_PIOB->PIO_PER = RIGHT;
- AT91C_BASE_PIOB->PIO_OER = RIGHT;
- }
- int main() {
- set_number_table();
- unlock_ports();
- while(1) {
- counter99();
- //counter9();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement