チーム2122

課題名

音あてゲーム

研究者名

2-15-23 Yuki Kidera
2-15-20 Yuki Kato

使用部品

基盤、PSoCミニプラグ、キーボード、LCD

概要

ランダムでドレミファソラシドのうち一音を出し、キーボードからの入力で音をあてる。
音があっていたらLCDにCongratulationと表示される。


ソースコード


#include <m8c.h> // part specific constants and macros
#include "PSoCAPI.h" // PSoC API definitions for all User Modules
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define SW 0b00010000
int PW=125; // Pulse Width
int SILENT=0, d=229, l=204, m=182, f=172, s=153, r=136, c=121, j=115; //Scale
int a[8] = {229,204,182,172,153,136,121,115};
void main(void)
{
  // M8C_EnableGInt ; // Uncomment this line to enable Global Interrupts
   // Insert your main routine code here.
   char* strPtr;
   char t;
   int i;
   unsigned int adc_data;
   UART_CmdReset();
   UART_IntCntl(UART_ENABLE_RX_INT);
   Counter8_WritePeriod(155);
   Counter8_WriteCompareValue(77);
   Counter8_Start();
   
   //
   PGA_Start(PGA_HIGHPOWER);
  ADCINC_Start(ADCINC_HIGHPOWER);
  ADCINC_GetSamples(0);
  
  LCD_Start();//LCDの表示
  LCD_PrCString("Push the Switch!!");
  
  //SWボタンが押されたらランダムのシード値を決定する。
  PRT1DR &= (~SW);
  while(1){
      if(PRT1DR & SW)
      {
         while(ADCINC_fIsDataAvailable()==0);
         adc_data=ADCINC_wClearFlagGetData();
          break;
      }
      else{
         while(ADCINC_fIsDataAvailable()==0);
         adc_data=ADCINC_wClearFlagGetData();
         PRT1DR &=(~SW);
      }
  }
  srand(adc_data);
   
   //int i = random 0~7;
   i = rand() % 8;
   PWM16_1_WritePeriod(a[i]);
   if(i == 0)
       t = 'd';
   else if(i == 1)
       t = 'l';
   else if(i == 2)
       t = 'm';
   else if(i == 3)
       t = 'f';
   else if(i == 4)
       t = 's';
   else if(i == 5)
       t = 'r';
   else if(i == 6)
       t = 'c';
   else if(i == 7)
       t = 'j';
   while(1){
   if(UART_bCmdCheck()){
       if(strPtr = UART_szGetParam()){
           UART_CPutString("Found valid command\r\nCommand =>");
           UART_PutString(strPtr);
           UART_CPutString("<\r\nParamaters;\r\n");
           while(strPtr = UART_szGetParam()){
               UART_CPutString(" <");
               UART_PutString(strPtr);
               UART_CPutString(">\r\n");
               if(*strPtr == t)
                   LCD_Start();
                   LCD_Position(0,0);
                   LCD_PrCString("Congratulation !!");
               }
           }
           UART_CmdReset();
       }
   }
}


考察

今回LCD以外は動作しなかった。コンパイルなどのエラーはなかったがこのような状態になったのでC言語にによるプログラムが違うのかportのつなぎ方に問題があるか、ユーザーモジュールのプロパティーの値に問題があると考えられる。これを直すには一つ一つの機能を分離させてテストしてどの機能が実装されていないのか調べる必要がある。

参考文献

チーム155A
チーム1721

  • 最終更新:2021-06-15 17:18:50

このWIKIを編集するにはパスワード入力が必要です

認証パスワード