adsense

顯示具有 嵌入式 標籤的文章。 顯示所有文章
顯示具有 嵌入式 標籤的文章。 顯示所有文章

2012-05-02

嵌入式 三個交叉點


第一個交叉點 畢一聲
第二個 轉180
第三個 停下來 畢三聲


'InnobotLineTracker.inb: Innobot Follow The Black Line
#DEFINE R_NORMAL_SPEED 80     'Set Innobot Normal Speed
#DEFINE L_NORMAL_SPEED 70
#DEFINE ERROR_1     90 'Define Error for each Sensor Value
#DEFINE ERROR_2     60
#DEFINE ERROR_3     40
#DEFINE ERROR_4     0
#DEFINE ERROR_5   -40
#DEFINE ERROR_6   -60
#DEFINE ERROR_7   -80
Const Frequency As Word = 1047
Sub Main()
Dim I,Sensor As Byte
Dim R, L, Err,j,k,a,b As Integer    
Low 10: Low 11

DO
Sensor=(In(7)<<2)+(In(8)<<1)+In(9) 'Combine L,M,R Sensor State to Sensor Variable
Sensor=(~Sensor) AND &B00000111
Select Sensor 'Select Modified Parameter By Sensor
Case &B100
Err = ERROR_2
Case &B110
Err = ERROR_3
      Case &B010
Err = ERROR_4
        Case &B011
Err = ERROR_5
        Case &B001
Err = ERROR_6
        Case &B000
If Err<1 Then
    Err = ERROR_7
Elseif Err>1 Then
    Err = ERROR_1
End If
Case &B111
            Err = ERROR_4
j+=1
Select j
Case 1
    Sound(12,200,1047)
    Case 2
    For k=1 To 38*2 'U Turn'
  Pulseout(10,250):Pulseout(11,250)
Sound(12,16,1047)
Next k
  Case 3
    For a=0 To 3 Step a+1
  Sound(12,400,768)
    Next a
    PAUSE(1000000)
  End Select
         End Select
R = (300+R_NORMAL_SPEED) + Err
        L = (300-L_NORMAL_SPEED) + Err
    Pulseout(10,L): Pulseout(11,R): PAUSE(16) 'Output control Signal
Loop
End Sub

2012-04-25

紅外線感測 走線


'InnobotLineTracker.inb: Innobot Follow The Black Line
#DEFINE R_NORMAL_SPEED 50     'Set Innobot Normal Speed
#DEFINE L_NORMAL_SPEED 40
#DEFINE ERROR_1     60 'Define Error for each Sensor Value
#DEFINE ERROR_2     30
#DEFINE ERROR_3     10
#DEFINE ERROR_4     0
#DEFINE ERROR_5   -10
#DEFINE ERROR_6   -30
#DEFINE ERROR_7   -60
Sub Main()
Dim I,Sensor As Byte
Dim R, L, Err As Integer    
Low 10: Low 11

DO
Sensor=(In(7)<<2)+(In(8)<<1)+In(9) 'Combine L,M,R Sensor State to Sensor Variable
Sensor=(~Sensor) AND &B00000111
Select Sensor 'Select Modified Parameter By Sensor
Case &B100
Err = ERROR_2
Case &B110
Err = ERROR_3
      Case &B010
Err = ERROR_4
        Case &B011
Err = ERROR_5
        Case &B001
Err = ERROR_6
        Case &B000
If Err<1 Then
    Err = ERROR_7
Elseif Err>1 Then
    Err = ERROR_1
End If
Case &B111
            Err = ERROR_4
Pause(2000) 'Wait 2 Sec.
            For I=1 To 10 'Go Forward
    Pulseout(10,300-L_NORMAL_SPEED)
    Pulseout(11,300+R_NORMAL_SPEED)
    PAUSE(16)
    Next I
         End Select
R = (300+R_NORMAL_SPEED) + Err 'Set Right Servo Parameter
        L = (300-L_NORMAL_SPEED) + Err 'Set Left Servo Parameter
    Pulseout(10,L): Pulseout(11,R): PAUSE(16) 'Output control Signal
Loop
End Sub

2012-04-18

嵌入式 超音波


'SonarATest.inb : SonarA Module Test Program
Const Frequency As Word = 1047
Peripheral MySonar As SonarA @ 3 'Set Module Name,Type, And ID
Dim Distance As Word
Sub main()
Do
MySonar.Ranging() '通知超音波模組開始量測
Pause(100)
MySonar.GetDistance(1,Distance) '讀取量測結果 1=回傳距離單位
Debug CLS,"Distance =", Distance,"cm",CR
If (Distance<15 And Distance>10) Then
Sound(12,200,Frequency):Pause (100)
Else If(Distance<10)Then
Sound(12,100,Frequency):Pause (20)
End If
End If
Loop
End Sub

2011-10-20

[嵌入式] 往右抹去


/*
 *  Copyright (C) 2008 by National Chip Implementation Center
 *  Author: ycchang <yaochung@cic.org.tw>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "EX_LCD_V.h"
#include "image.h"
#include "image1.h"

#define DELAY_TIME 100000

unsigned int base = 0x10000000;
int LCDHSize  = 320, LCDVSize = 240, PixelSize = 3;
char *image;

void clean_screen();
void delay(unsigned int);
void move_right();
void move_rightdown();

int main()
{
    int i,j,k;
    int flag = 0;

    //uart_init ();

    /* turn on lcd */
    lcdc_init ();

    memset ((char *) base, 0xff, LCDHSize*LCDVSize*PixelSize);
    // clean screen
    clean_screen();

    // show images
    LCDC_FRAMEBASE = base;
    while (1) {
     flag ^= 1;
     image = (flag) ? imagebits : imagebits1;

for (i=0; i<LCDHSize; i++)
          for (j=0; j<LCDVSize; j++) {
             for (k=0; k<PixelSize; k++)
                 (*((char *)(base + j * LCDHSize * PixelSize + i * PixelSize + k))) =
                 image[j * LCDHSize * PixelSize + i * PixelSize + k];
        }
     // show onto LCD
LCDC_FRAMEBASE = base;
        delay(DELAY_TIME);
     }
exit (0);
//while (1);
}

// clean screen
void clean_screen()
{
    int i,j,k;
  
for (i=0; i<LCDVSize; i++)
        for (j=0; j<LCDHSize; j++) {
            for (k=0; k<PixelSize; k++)
                (*((char *)(base + i * LCDHSize * PixelSize + j * PixelSize + k))) = 0x00;
        }
    // show onto LCD
LCDC_FRAMEBASE = base;
}

// delay time
void delay(unsigned int count)
{
    for(;count>0;count--)
        ;
}