پاسخ : شتاب سنج ADXL345 فروشگاه [فیلم+توضیحات+سوالات]
سلام به همگی
میشه کد پروژه اجرا شده را بهم بدید؟
بهش خیلی احتیاج دارم
مرسی از دوستان
سلام به همگی
میشه کد پروژه اجرا شده را بهم بدید؟
بهش خیلی احتیاج دارم
مرسی از دوستان
$regfile = "m64def.dat" $crystal = 7372800 '$baud1 = 9600 Config Pinb.5 = Output Config Pinb.6 = Output Config Pinb.7 = Output Config Pind.6 = Input Config Pind.7 = Input Config Com2 = 115200 , Synchrone = 0 , Parity = None , Stopbits = 2 , Databits = 8 , Clockpol = 0 'Config Serialout = Buffered , Size = 30 'Clear Serialout Config Serialout = Normal Config Timer0 = Timer , Prescale = 64 Stop Timer0 Config Int6 = Falling Config Int7 = Falling Config Scl = Portd.0 Config Sda = Portd.1 Config Pind.5 = Input Adxl_cs Alias Portd.5 Led1 Alias Portb.5 Led2 Alias Portb.6 Led3 Alias Portb.7 'Sfior = Sfior And &B11111011 'Set Portd.6 'Set Portd.7 Enable Interrupts 'Enable Serial Enable Int6 On Int6 Int6_isr Enable Int7 On Int7 Int7_isr Enable Ovf0 On Ovf0 Ovf0_isr Reset Led1 Reset Led2 Reset Led3 Open "com2:" For Binary As #2 'Clear Serialout I2cinit Waitms 500 Set Led1 Set Led2 Set Led3 Const Adxl_add_write = &HA6 Const Adxl_add_read = &HA7 Dim A As Byte Dim B As Word Dim C As Byte Dim D As Byte Dim Tick_1s As Bit Dim Tick_5s As Bit Dim X_low As Byte Dim X_high As Byte Dim Y_low As Byte Dim Y_high As Byte Dim Z_low As Byte Dim Z_high As Byte Dim X As Word Dim Y As Word Dim Z As Word A = 0 Reset Tick_1s Reset Tick_5s Set Portb.5 Wait 1 Reset Portb.5 Wait 1 Set Portb.5 'Wait 1 Print #2 , "Initializing ADXL345..." 'Wait 1 Reset Portb.5 Print #2 , "ADXL345 goes in to I2C mode" Set Adxl_cs 'Wait 1 I2cstart I2cwbyte Adxl_add_write I2cwbyte &H00 I2cstart I2cwbyte Adxl_add_read I2crbyte A , Nack I2cstop If A = 229 Then Print #2 , "ADXL345 responded" End If Waitms 500 I2cstart I2cwbyte Adxl_add_write I2cwbyte &H2D I2cwbyte &H00 I2cstop Waitms 500 'initialize for Activity andinactivity interrupt I2cstart I2cwbyte Adxl_add_write I2cwbyte &H24 I2cwbyte &HA0 I2cwbyte &H45 I2cwbyte &H03 I2cwbyte &H77 I2cstop Waitms 500 I2cstart I2cwbyte Adxl_add_write I2cwbyte &H2E I2cwbyte &H18 I2cwbyte &H08 I2cstop Waitms 500 I2cstart I2cwbyte Adxl_add_write I2cwbyte &H31 I2cwbyte &H09 I2cstop Waitms 500 I2cstart I2cwbyte Adxl_add_write I2cwbyte &H2D I2cwbyte &H08 I2cstop Wait 1 'Print #2 , A 'Wait 1 A = 0 Start Timer0 Do If Tick_1s = 1 Then Print #2 , A Incr A Toggle Portb.5 Reset Tick_1s End If If Pind.6 = 1 Then Reset Led2 Else Set Led2 End If If Pind.7 = 1 Then Reset Led3 Else Set Led3 End If Loop End 'end program Ovf0_isr: If B < 450 Then Incr B Else B = 0 Incr C Set Tick_1s End If If C = 5 Then C = 0 Set Tick_5s End If Return Int6_isr: Waitms 10 I2cstart I2cwbyte Adxl_add_write I2cwbyte &H2E I2cstart I2cwbyte Adxl_add_read I2crbyte C , Nack 'I2crbyte D , Nack I2cstop Print #2 , "Int6: " ; C ; " " ; D Return Int7_isr: Waitms 10 I2cstart I2cwbyte Adxl_add_write I2cwbyte &H30 I2cstart I2cwbyte Adxl_add_read I2crbyte C , Nack I2cstop Print #2 , "Int7: " ; C Return
دیدگاه