チーム1222

課題名

カウンター(仮)

研究者名

2年15組2番 秋澤 英輔
2年15組11番 岸川 哲也

概要

gpio_pollラボを少しいじった。
スイッチを押した回数をカウントし、LCDに表示するやつです。
上にカウントした値を16進数で表示。用途は不明。
下にカウントした値を10進数で表示。用途しかない。
リセットでカウントリセット。
スイッチを1万回押すと下にOtukareと表示される。

ソース


#include <m8c.h> // part specific constants and macros
#include "PSoCAPI.h" // PSoC API definitions for all User Modules
#define SW 0b00010000

#define LED 0b00000001

void BytetoIntStr(int c, int keta, char *buf) {
  int i;
   buf[keta+1] = '\0';
   buf[0] = (c < 0)? '-': ' ';
   c = (c < 0)? -c: c;
  if(c == 0){
  LCD_1_Position(1,0);
  LCD_1_PrCString(" ");
  buf[0] = '0';
  for (i = keta; i > 0; i--) {
       buf[i] = (c > 0)? ((c % 10) + '0'): ' ';
       c /= 10;
   }
}

void main()
{
  // M8C_EnableGInt ; // Uncomment this line to enable Global Interrupts
   // Insert your main routine code here.
   int count=0;
   int scount = 0;
   char intstr[7];
   PRT1DR &=(~SW);
   LCD_1_Start();
   while(1){
   
       if(PRT1DR & SW){
           if(scount == 0){
            count++;
            scount = 1;
           }
            PRT1DR &=(~LED);
           PRT1DR &=(~SW);
       }
       else{
           PRT1DR |=LED;
           PRT1DR &=(~SW);
           scount = 0;
       }
       
       LCD_1_Position(0,0);
       LCD_1_PrHexInt(count);
       LCD_1_Position(1,0);
       BytetoIntStr(count,3,intstr);
       if(count == 10001){
        LCD_1_Start();
          LCD_1_Position(1,0);
       LCD_1_PrString(intstr);
         }
      else if(count != 10000){
        LCD_1_PrString(intstr);
         }
      else{
        LCD_1_PrCString("Otukare");
        LCD_1_Position(1,0);
         }
      
   }
}

使用部品

PSoC
MiniProg
ジャンパー線(1本)

考察

TAさんと近辺の人の手を借りつつ作った。
2進数表示はあえてやらなかった。できなかったから。
16進数を10進数に変換して表示する(関数は調べて、少し文を追加しました)のと、
スイッチのチャタリング対策(近辺の人仕様)が重要な要素になった思う。
強いて言えば、シンプル過ぎたようにも思う。

  • 最終更新:2012-06-12 16:31:55

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

認証パスワード