طراحی و ساخت قفل الکترونيکي

رديابي گوشی همراه

كنترل هوشمند چهارراه

طراحی و ساخت مين ياب هوشمند

ادامه 

برنامه پروژه موجود در کتاب برای نمایش فرکانس

در زیر بخشی از برنامه مربوط به نمایش فرکانس کار موتور و کنترل درایو  آورده شده است.

 

$regfile = "M32DEF.dat"                                     'internal crystal 8000000

Config Lcdpin = Pin , Db4 = Portc.1 , Db5 = Portc.2 , Db6 = Portc.3 , Db7= _

Portc.4 , E = Portd.2 , Rs = Portd.3

Config Lcd = 16 * 2

Config Timer1 = Counter , Edge = Rising

Ddrb.1 = 0 : Portb.1 = 1                                    'PULL UP RESISTOR ACTIVATED

Config Timer0 = Timer , Prescale = 1024

Enable Counter1

Enable Interrupts

Enable Timer0

Enable Timer1

On Ovf1 Pulsecount

On Ovf0 Ovf0occures

Dim A As Long , I As Long , B As Byte

B = 0

Cls

Start Timer0

Do

 

Loop

End                                                         'end program

 

Ovf0occures:

Incr I

If I > 30 Then

Stop Timer0

Cls : Home

A = B * 65536

A = A + Counter1

Lcd "FREQ IS :" ; A ; "HZ"   

Lcd "Yari "

B = 0

I = 0 : Counter1 = 0

Start Timer0

End If

Return

 

Pulsecount:

Incr B

Counter1 = 0

Return

……………………………………………………………………………………………….......

Dim A As Byte

Config Kbd = Portb , Debounce = 50 , Delay = 255

Cls

Home

Do

 A = Getkbd()

 A = Lookup(a , Read_key)

 If A < 16 Then

  Select Case A

  Case 0 To 9:                                              'number0...9

   Lcd A

  Case 10:                                                  'F1(backspace)

   Shiftcursor Left

   Lcd" "

   Shiftcursor Left

  Case 11:                                                  'F2(space)

   Shiftcursor Right

  Case 12:                                                  'F3

   Home

  Case 13:                                                  'F4

   Locate 1 , 16

  Case 14:                                                  'ENTER(NEXT LINE)

   Home L

  Case 15:

   Cls                                                      'set(clearscreen)

 End Select

End If

Loop

End                                                         'end program

Read_key:

Data 13 , 14 , 0 , 15 , 12 , 9 , 8 , 7 , 11 , 6 , 5 , 4 , 10 , 3 , 2 , 1

…………………………………………………………………………………………………..

$baud = 9600

Config Serialout = Buffered , Size = 255

Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = _ Portc.7 , E = Portc.3 , Rs = Portc.2

Config Sda = Portc.0

Config Scl = Portc.1

Config I2cdelay = 1

Config Kbd = Porta

Declare Sub Readeepromserial

Const Eewrite = 160

Const Eeread = 161

Dim A As Byte

Dim B As Byte

Dim Address As Word

Lcd "Start Reading…"

Address = &H0000

While Address < &H7FFF

      A = High(address)

      Print "a:" ; Hex(a)

      B = Low(address)

      Print "b:" ; Hex(b)

      Call Readeepromserial

      Print Address

Wend

End                                                         'end program

 

Sub Readeepromserial

      I2cstart

      I2cwbyte Eewrite

      I2cwbyte A

      I2cwbyte B

      I2cstart

      I2cwbyte Eeread

      I2crbyte A , Nack

      I2cstop

      Print A

Incr Address

End Sub Readeepromserial

...................................................................................................................................................................$regfile = "m32def.dat"

$crystal = 8000000

Config Timer1 = Pwm , Prescale = 8 , Pwm = 10 , Compare A Pwm = Disconnect, _

Compare B Pwm = Clear Down

Config Pind.4 = Output

Config Lcdpin = Pin , Db4 = Portc.1 , Db5 = Portc.2 , Db6 = Portc.3 , Db7= _

Portc.4 , E = Portd.2 , Rs = Portd.3

Config Lcd = 16 * 2

$baud = 9600

Enable Urxc

Enable Interrupts

On Urxc Ao_value_from_serial_port

Dim Serial_data(3) As Byte

Dim I As Integer

Dim Ao As Word

Dim Ao_mv As Word

Dim Msb_ao As Byte

Dim Lsb_ao As Byte

Dim Flag As Bit

Dim Cs As Byte

Dim Count As Byte

Dim Ao_output As Single

Dim Uart As Byte

Cls

'120 digital =2.5v

'430        =9.0v

Home

Lcd "Ao=" ; "2000" ; "mv " ; "PWM=" ; Pwm1b; " "

Locate 2 , 1

Lcd " Analog Out Proj"

Do

Loop

End                                                         'end program

 

Ao_value_from_serial_port:                                  'uart data reciving interrupt

Uart = Udr                                                  'reading uart data register (udr)

If Flag = 0 Then

   If Uart = &HAA Then                                      'finding the first byte of frame

      Cs = &HAA

      Flag = 1

      Count = 1

   End If

Else

   Serial_data(count) = Uart

 

   If Count = 3 Then                                        'counting 3 byte after detecting first byte

      If Cs = Serial_data(3) Then                           'compare calculated cs with reciving cs

         Lsb_ao = Serial_data(1)                            'the cs is good   byte 2 if lsb

         Msb_ao = Serial_data(2)                            'the cs is good   byte 3 if msb

         Ao = Makeint(lsb_ao , Msb_ao)                      'making word

         Ao_mv = Ao

         Ao_output = Ao * 0.0477                            'pwm value calculation

         Ao = Int(ao_output)

         Pwm1b = Ao                                         'send pwm

         Home

         Lcd "Ao=" ; Ao_mv ; "mv " ; "PWM=" ; Pwm1b ; " "   'show pwm & Ao

         Locate 2 , 1

         Lcd " Analog Out Proj"

      End If

   Count = 0                                                'reset serial data counter

   Flag = 0

   End If

Incr Count

Cs = Cs + Uart                                              'cs(check sum) calculation

End If

Return

End

…………………………………………………………………………………………………..

برنامه مربوط به 8051

 

KEYCODNUMBER                   EQU     30H

KEYCODASCI                     EQU     31H

BUFFERLCD                      EQU     32H

DELAYREP                       EQU     33H

NUM1                           EQU     34H

NUM2                           EQU     35H

NUM3                           EQU     3CH                     

BUFFERKEY                      EQU     36H

BUFFERROTATE                   EQU     37H

BUFNUMBER                      EQU     38H

ROTATENUMBER                   EQU     39H

SPEEDNUMBER                    EQU     3AH

GAMREP                         EQU     3BH

LCDRS                          BIT     P3.5

LCDRW                          BIT     P3.6

LCDE                           BIT     P3.7

ROW1                                   BIT     P1.0

ROW2                           BIT     P1.1

ROW3                           BIT     P1.2

ROW4                           BIT     P1.3

COL1                           BIT     P1.4

COL2                           BIT     P1.5

COL3                           BIT     P1.6

STEPPERPORT                    EQU     P3

LCDDATAP                       EQU     P2

ORG 0000H

MAIN:

MOV TMOD,#01H

CALL CLS

CALL  BEEP

CALL MSGHI

MOV DELAYREP,#20

CALL DELAY

CALL  BEEP

; START PROGRAM

START:

CALL  BEEP

MOV 20H,#0H            ;SET DEFAULT  SETTING

MOV 21H,#0H            ;SET DEFAULT  SETTING

CALL CLS

                      ;  ROTATENUMBER

CALL MSGROTATE         ;

CALL KEYSCAN

MOV NUM1,KEYCODNUMBER

CALL DATALCD                          

MOV DELAYREP,#12

CALL DELAY

CALL KEYSCAN

MOV NUM2,KEYCODNUMBER

CALL DATALCD                          

MOV DELAYREP,#12

CALL DELAY

CALL KEYSCAN

MOV NUM3,KEYCODNUMBER

CALL DATALCD                           ;

MOV DELAYREP,#12

CALL DELAY

CALL CONVERTTONUMBER

MOV ROTATENUMBER,BUFNUMBER

CALL  BEEP                                             ;   SPEEDNUMBER

CALL MSGSPEED

CALL KEYSCAN

MOV NUM1,KEYCODNUMBER

CALL DATALCD                           ;

MOV DELAYREP,#12

CALL DELAY

CALL KEYSCAN

MOV NUM2,KEYCODNUMBER

CALL DATALCD                           ;

MOV DELAYREP,#12

CALL DELAY

CALL KEYSCAN

MOV NUM3,KEYCODNUMBER

CALL DATALCD                         

MOV DELAYREP,#12

CALL DELAY

CALL CONVERTTONUMBER

MOV SPEEDNUMBER,BUFNUMBER

CALL  BEEP                      

;                                      LEFT OR RIGHT

MOV DELAYREP,#15

CALL DELAY

CALL CLS

CALL MSGLEFTRIGHT

ROTATELOOP:

MOV P1,#0FFH

CLR ROW1

JNB COL3,KL

JNB COL1,KR

JNB COL2,RESTART

JMP ROTATELOOP

KL:

CALL  ROTATERIGHT

JMP  START

KR:

CALL  ROTATELEFT

JMP   START

RESTART:

CALL DELAY

JMP START

;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;                              SPEED DELAY

SPEED:

MOV R7,SPEEDNUMBER

LOOPSPEED:

MOV TH0,#0FCH                  ;SET TIMER0  FOR  1MS DELAY

MOV TL0,#18H

SETB TR0

LOOPSPTF:JNB TF0,LOOPSPTF

CLR TR0

CLR TF0

;-------------------------------PAUSE TEST

CLR ROW4

JNB COL3,PAUSE

SETB ROW4

;-------------------------------

INC R7

CJNE  R7,#103,LOOPSPEED

MOV R7,#00H

RET

;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;                               PAUSE

PAUSE:

CALL CLS

CALL MSGPAUSE

CLR ROW4

PAUSELOOP:JNB COL3,PAUSELOOP

PAUSELOOP2:JB COL1,PAUSELOOP2  ;WAITE FOR PERESS UP

SETB ROW4

MOV DELAYREP,#12

CALL DELAY

CALL CLS

CALL COUNTINUE

RET

;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;                      DELAY    

DELAY:

MOV R6,DELAYREP

LOOPDELAYMAIN:

MOV TH0,#3CH                                   ;5OMS DELAY

MOV TL0,#0B0H

SETB TR0

LOOPDELAY:JNB TF0,LOOPDELAY       ;TF0 FLAG TEST

CLR TF0

CLR TR0

DJNZ R6,LOOPDELAYMAIN

RET

;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;                             RIGHT

ROTATERIGHT:

SETB ROW1

RRR:

MOV  DELAYREP,#12

CALL CLS

CALL MSGRIGHT

MOV BUFFERROTATE,ROTATENUMBER

LOOPRIGHT:

MOV GAMREP,#50

LOOPGAMR:

MOV STEPPERPORT,#00001001B

CALL SPEED

MOV STEPPERPORT,#00001100B

CALL SPEED

MOV STEPPERPORT,#00000110B

CALL SPEED

MOV STEPPERPORT,#00000011B

CALL SPEED

DJNZ GAMREP,LOOPGAMR

DJNZ BUFFERROTATE,LOOPRIGHT

JMP START

;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 REPETR: JMP RRR                      ;     LEFT

ROTATELEFT:

SETB ROW1

REPETL:

MOV  DELAYREP,#12

CALL CLS

CALL MSGLEFT

MOV BUFFERROTATE,ROTATENUMBER

LOOPLEFT:

MOV GAMREP,#50

LOOPGAM:

MOV STEPPERPORT,#00000011B

CALL SPEED

MOV STEPPERPORT,#00000110B

CALL SPEED

MOV STEPPERPORT,#00001100B

CALL SPEED

MOV STEPPERPORT,#00001001B

CALL SPEED

DJNZ GAMREP,LOOPGAM

DJNZ BUFFERROTATE,LOOPLEFT

JMP START

;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;                             KEYSCAN

KEYSCAN:

MOV P1,#0FFH

CLR ROW1

JNB COL1,KEY1

JNB COL2,KEY2

JNB COL3,KEY3

SETB ROW1

CLR ROW2

JNB COL1,KEY4

JNB COL2,KEY5

JNB COL3,KEY6

SETB ROW2

CLR ROW3

JNB COL1,KEY7

JNB COL2,KEY8

JNB COL3,KEY9

SETB ROW3

CLR ROW4

JNB COL1,REPETL

JNB COL2,KEYZERO

JNB COL3,REPETR

SETB ROW4

JMP KEYSCAN

KEY1:

MOV KEYCODNUMBER,#1

MOV KEYCODASCI,#'1'

RET

KEY2:

MOV KEYCODNUMBER,#2

MOV KEYCODASCI,#'2'

RET

KEY3:

MOV KEYCODNUMBER,#3

MOV KEYCODASCI,#'3'

RET

KEY4:

MOV KEYCODNUMBER,#4

MOV KEYCODASCI,#'4'

RET

KEY5:

MOV KEYCODNUMBER,#5

MOV KEYCODASCI,#'5'

RET

KEY6:

MOV KEYCODNUMBER,#6

MOV KEYCODASCI,#'6'

RET

KEY7:

MOV KEYCODNUMBER,#7

MOV KEYCODASCI,#'7'

RET

KEY8:

MOV KEYCODNUMBER,#8

MOV KEYCODASCI,#'8'

RET

KEY9:

MOV KEYCODNUMBER,#9

MOV KEYCODASCI,#'9'

RET

KEYZERO:

MOV KEYCODNUMBER,#0

MOV KEYCODASCI,#'0'

RET

;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;                            CLS

CLS:

MOV  BUFFERLCD,#38H

CALL COMMAND

MOV BUFFERLCD,#0CH                   

CALL COMMAND

MOV BUFFERLCD,#01H

CALL COMMAND

MOV  BUFFERLCD,#02H

CALL COMMAND

MOV BUFFERLCD,#80H

CALL COMMAND

RET

;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;                             COMMAND LCD

COMMAND:

CALL READY

MOV LCDDATAP,BUFFERLCD

CLR LCDRS

CLR LCDRW

SETB LCDE

NOP

NOP

CLR LCDE

RET

;=============================================================

;                            DATA LCD

DATALCD:

CALL READY

MOV LCDDATAP,KEYCODASCI

SETB LCDRS

CLR LCDRW

SETB LCDE

NOP

NOP

CLR LCDE

RET

;=============================================================

;                                READY

READY:

SETB P2.7

CLR LCDRS

SETB LCDRW

  BACK:

        CLR LCDE

        NOP

        SETB LCDE

  JB P2.7,BACK

RET

;/////////;/////////;/////////

CONVERTTONUMBER:

MOV A,NUM1

MOV B,#10

MUL AB

MOV B,NUM2

ADD A,B

MOV B,#10

MUL AB

MOV B,NUM3

ADD A,B

MOV BUFNUMBER,A

RET

;/////////;/////////;/////////

MSGLEFT:

MOV KEYCODASCI,#'L'

CALL DATALCD

MOV KEYCODASCI,#'E'

CALL DATALCD

MOV KEYCODASCI,#'F'

CALL DATALCD

MOV KEYCODASCI,#'T'

CALL DATALCD

MOV BUFFERLCD,#0C0H

CALL COMMAND

MOV KEYCODASCI,#'<'

 

نور پردازي پل كابلي تبريز

روشنايي بيلبوردهاي جاده اي شيراز

نصب سيستم برق اضطراري (UPS) نداجا

طراحي سيستم اضطراري (LED) براي پتروشيمي تبريز

 ساير پروژه هاي انجام شده