SHARE
TWEET

Untitled

a guest May 19th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* ###################################################################
  2. **     Filename    : main.c
  3. **     Project     : 2
  4. **     Processor   : MKL46Z256VLL4
  5. **     Version     : Driver 01.01
  6. **     Compiler    : GNU C Compiler
  7. **     Date/Time   : 2019-04-18, 11:33, # CodeGen: 0
  8. **     Abstract    :
  9. **         Main module.
  10. **         This module contains user's application code.
  11. **     Settings    :
  12. **     Contents    :
  13. **         No public methods
  14. **
  15. ** ###################################################################*/
  16. /*!
  17. ** @file main.c
  18. ** @version 01.01
  19. ** @brief
  20. **         Main module.
  21. **         This module contains user's application code.
  22. */        
  23. /*!
  24. **  @addtogroup main_module main module documentation
  25. **  @{
  26. */        
  27. /* MODULE main */
  28.  
  29.  
  30. /* Including needed modules to compile this module/procedure */
  31. #include "Cpu.h"
  32. #include "Events.h"
  33. /* Including shared modules, which are used for whole project */
  34. #include "PE_Types.h"
  35. #include "PE_Error.h"
  36. #include "PE_Const.h"
  37. #include "IO_Map.h"
  38. /* User includes (#include below this line is not maintained by Processor Expert) */
  39.  
  40.  
  41. void display7seg(int i){
  42.  
  43.  
  44.       //カウントした値を7segに出力する
  45. if((i >> 3) & 1) {
  46.     GPIOB_PSOR = (1<<3);
  47. }else{
  48.     GPIOB_PCOR = (1<<3);
  49. }
  50. if((i >> 2) & 1) {
  51.     GPIOB_PSOR = (1<<2);
  52. }else{
  53.     GPIOB_PCOR = (1<<2);
  54. }
  55. if((i >> 1) & 1) {
  56.     GPIOB_PSOR = (1<<1);
  57. }else{
  58.     GPIOB_PCOR = (1<<1);
  59. }
  60. if(i & 1) {
  61.     GPIOB_PSOR = (1<<0);
  62. }else{
  63.     GPIOB_PCOR = (1<<0);
  64. }
  65. }
  66. /*lint -save  -e970 Disable MISRA rule (6.3) checking. */
  67. int main(void)
  68. /*lint -restore Enable MISRA rule (6.3) checking. */
  69. {
  70.   /* Write your local variable definition here */
  71.     int i=0;
  72.     int pta1_pushing=0;
  73.   /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  74.   PE_low_level_init();
  75.   /*** End of Processor Expert internal initialization.                    ***/
  76.  
  77.   /* Write your code here */
  78.   /* For example: for(;;) { } */
  79.   /* Write your code here */
  80.     SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK; // PTA のクロックを有効にする
  81.     PORTA_PCR1 = PORT_PCR_MUX(1); // PTA1 を GPIO に設定する
  82.     GPIOA_PDDR &= ~(1<<1); // PTA1 を入力に設定する
  83.     SIM_SCGC5 |= SIM_SCGC5_PORTD_MASK; // PTDのクロックを有効にする
  84.     PORTD_PCR5 = PORT_PCR_MUX(1);
  85.     GPIOD_PDDR |= (1<<5);
  86.     SIM_SCGC5 |= SIM_SCGC5_PORTE_MASK; // PTEのクロックを有効にする
  87.     PORTE_PCR29 = PORT_PCR_MUX(1);
  88.     GPIOE_PDDR |= (1<<29);
  89.     SIM_SCGC5 |= SIM_SCGC5_PORTB_MASK;
  90.     PORTB_PCR0 = PORT_PCR_MUX(1); // PTB0をGPIOに設定する
  91.     GPIOB_PDDR |= (1<<0); //PTB0を出力に設定する
  92.     PORTB_PCR1 = PORT_PCR_MUX(1); // PTB1をGPIOに設定する
  93.     GPIOB_PDDR |= (1<<1); //PTB1を出力に設定する
  94.     PORTB_PCR2 = PORT_PCR_MUX(1); // PTB2をGPIOに設定する
  95.     GPIOB_PDDR |= (1<<2); //PTB2を出力に設定する
  96.     PORTB_PCR3 = PORT_PCR_MUX(1); // PTB3をGPIOに設定する
  97.     GPIOB_PDDR |= (1<<3); //PTB3を出力に設定する
  98.  
  99.  
  100.     //プッシュスイッチの状態がOFFになるまでループで待つ
  101.     while(1){
  102.       bool pta1_val = GPIOA_PDIR&(1<<1)? 1 : 0;
  103.       if(pta1_val == 0){
  104.         //7セグメントLEDに0(初めに表示するべき値)を表示する
  105.            GPIOB_PCOR = (1<<0);
  106.            GPIOB_PCOR = (1<<1);
  107.            GPIOB_PCOR = (1<<2);
  108.            GPIOB_PCOR = (1<<3);
  109.            break;
  110.       }
  111.     }
  112.  
  113.  
  114.  
  115.     //ここからメインループ。プッシュスイッチの状態がオンになるまでループで待つ
  116.     while(1){
  117.  
  118.       while(1){
  119.               bool pta1_val = GPIOA_PDIR&(1<<1)? 1 : 0;
  120.               if(pta1_val){
  121.                   if(pta1_pushing == 1){
  122.                       // nothing do
  123.                   }else{
  124.                       pta1_pushing = 1; //押下モードに移行
  125.                       i++;
  126.                     if(i == 10){
  127.                     i=0;
  128.                     }
  129.                       display7seg(i);
  130.                   }
  131.               }else{
  132.                   pta1_pushing = 0;
  133.               }
  134.      }
  135. }
  136.  
  137.   /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
  138.   /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
  139.   #ifdef PEX_RTOS_START
  140.     PEX_RTOS_START();                  /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
  141.   #endif
  142.   /*** End of RTOS startup code.  ***/
  143.   /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  144.   for(;;){}
  145.   /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
  146. } /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
  147.  
  148. /* END main */
  149. /*!
  150. ** @}
  151. */
  152. /*
  153. ** ###################################################################
  154. **
  155. **     This file was created by Processor Expert 10.5 [05.21]
  156. **     for the Freescale Kinetis series of microcontrollers.
  157. **
  158. ** ###################################################################
  159. */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top