Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "at91sam3x8.h"
- #include <stdlib.h>
- #include "system_sam3x.h"
- #define PIOC_PER (unsigned int *)(0x400E1200)
- #define PIOC_ODR (unsigned int *)(0x400E1214)
- #define PIOC_PDSR (unsigned int *)(0x400E123C)
- #define PIOC_OER (unsigned int *)(0x400E1210)
- #define PIOC_PDR (unsigned int *)(0x400E1204)
- #define PMC_PCER0 (unsigned int *)(0x400E0610)
- #define PMC_PCER1 (unsigned int *)(0x400E0700)
- #define PIOD_CODR (unsigned int *)(0x400E1434)
- #define PIOD_SODR (unsigned int *)(0x400E1430)
- #define PIOC_CODR (unsigned int *)(0x400E1234)
- #define PIOC_SODR (unsigned int *)(0x400E1230)
- #define PIOC_PUDR (unsigned int *)(0x400E1260)
- #define PIOD_PUDR (unsigned int *)(0x400E1460)
- void pins_int();
- int counter=0;
- unsigned int rows[4];
- unsigned int columns[3];
- int value=0;
- int col=0;// increase variabel för kolumnerna
- int row=0; // increase variabel för raderna
- void pins_int(){
- *PIOD_PER = 0xE;
- //*PMC_PCER1= (1<<13);// Ställer in Peripheral clock.
- *PIOC_PER= 0x3BC;// Enablar alla pins som raderna och kolumnerna.
- *PIOC_ODR= 0x3BC;//Disablar alla pins för raderna till output.
- *PIOC_OER= 0x380;
- *PIOD_CODR= 0x4;
- *PIOC_PUDR=0x380;
- *PIOD_PUDR=0xC;
- }
- int func(void){
- columns[0]=0x80;
- columns[1]=0x100;
- columns[2]=0x200;
- rows[0] = 0x4;
- rows[1] = 0x8;
- rows[2] = 0x10;
- rows[3] = 0x20;
- for(col=0;col<3 && value==0 ;col++){
- *PIOC_CODR=columns[col];
- for(row=0; row<4 && value==0;row++){
- if((*PIOC_PDSR & rows[row-1])==0){
- value=3*row+col+1;
- }
- *PIOC_SODR=columns[col];
- }
- }
- return(value);
- }
- /*Value = 0=Check
- Clear OE KEY BUS (Active Low)= Check
- Make all Column pin as output= Check
- Set all Column pin as high= Check
- Loop Column=Check
- Clear one column at the time=Check
- Loop Row=Check
- Read row and check if bit is zero=Check
- Value = Row*3+Col+1;=Check
- end loop Row=Check
- Set the column again=Check
- End loop Column=Check
- Make all Column pin as input=Check
- Return Value. =Check.*/
- int main()
- {
- pins_int();
- SystemInit();
- SysTick_Config(84000);
- while(1){
- func();
- }
- }
- void Systick_Handler(){
- counter++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement