Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "system_sam3x.h"
- #include "at91sam3x8.h"
- #include <stdio.h>
- int func()
- {
- unsigned int value = 0; //Return value
- *AT91C_PIOD_SODR = (0 << 2); //Enable/Clear OE pin
- //Make col pins as output
- *AT91C_PIOC_PER = (3 << 8);
- *AT91C_PIOC_PER = (1 << 12);
- *AT91C_PIOC_OER = (3 << 8);
- *AT91C_PIOC_OER = (1 << 12);
- *AT91C_PIOC_SODR = (3 << 8); //Set Colum pins all to 1
- *AT91C_PIOC_SODR = (1 << 12);
- for (int i = 0; i < 3; i++) //Col loop
- {
- if (i == 2)
- *AT91C_PIOC_CODR = (1 << 12); //Clear one col at a time/ Set it to zero
- else
- *AT91C_PIOC_CODR = (1 << 8+i); //Clear one col at a time/ Set it to zero
- for (int j = 0; j < 4; j++) //Row Loop
- {
- if (*AT91C_PIOC_PDSR & (1 << j+4) == 0) //Check if the bit is 0 if it is set the value equal to that button
- {
- value = (3*j+ i+1);
- }
- }
- *AT91C_PIOC_SODR = (3 << 8); //Make col pins high again
- *AT91C_PIOC_SODR = (1 << 12);
- }
- *AT91C_PIOC_CODR = (3 << 8); //Clear all pins and make them as input
- *AT91C_PIOC_CODR = (1 << 12);
- *AT91C_PIOC_ODR = (3 << 8);
- *AT91C_PIOC_ODR = (1 << 12);
- *AT91C_PIOD_SODR = (1 << 2); //Disable/Clear OE pin
- return value;
- }
- //Delay Function
- void Delay(int val)
- {
- for (int i = 0; i < val; i++)
- {
- asm("nop");
- }
- }
- //Read Status
- unsigned char Read_Status_Display(void)
- {
- unsigned char temp;
- }
- //Write command
- void Write_Command_2_Display_(unsigned char command)
- {
- }
- //Write Data
- void Write_data_2_Display(unsigned char data)
- {
- }
- //Display function
- int Display(void)
- {
- }
- int main()
- {
- SystemInit();
- //Enable Periphial Main Clock
- *AT91C_PMC_PCER = (3 << 13);
- //Set up the pins as correct output and inputs
- *AT91C_PIOC_PER = (0xF << 4);
- *AT91C_PIOC_ODR = (0xF << 4);
- *AT91C_PIOD_PER = (1 << 2);
- *AT91C_PIOD_PPUDR = (1 << 2);
- *AT91C_PIOD_OER = (1 << 2);
- while(1)
- {
- // ReadButton(&i);
- int val = func();
- if (val != 0)
- {
- asm("nop");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement