Dani_info

Cortex M0 Kinetis GPIO

Apr 22nd, 2025
540
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.49 KB | None | 0 0
  1. //enable clock
  2. SIM->SCGC5|=SIM_SCGC_PORTp_MASK;
  3.  
  4. //SET MUX
  5. //clear MUX bits
  6. PORTp->PCR[x]&=~PORT_PCR_MUX_MASK;
  7. //set mux bits as GPIO
  8. PORTp->PCR[x]|=PORT_PCR_MUX(1);
  9.  
  10. //set direction: 1-OUT; 0-IN
  11.  
  12. PORTp->PDDR|=1UL<<x; //OUT
  13. PORTp->PDDR&=~1UL<<x; //IN
  14.  
  15. //set OUT='high'
  16. PORTp->PSOR|=1UL<<x;
  17. //or
  18. PORTp->PDOR=1UL<<x;
  19.  
  20. //set OUT='low'
  21. PORTp->PCOR|=1UL<<x;
  22.  
  23. //toggle pin
  24. PORTp->PTOR|=1UL<<x;
  25.  
  26. //read pin level
  27.  
  28. if (PORTp->PDIR& (1UL<<x))
  29.     //if PORT p pin x execute this;
  30.  
Advertisement
Add Comment
Please, Sign In to add comment