Das Open-Control-Projekt - Die Alternative zur C-Control-I


Das Forum zur C-Control-1
Welche C-Control-Varianten existieren?
Übersicht - Suchen - Neueste 50 Beiträge - Neuer Beitrag - Login - Registrieren
INFO - FAQ - CC2-Forum - CCPro-Forum 

 COMPASS CMPS03 16 BIT BEARING DATA READ v1.3 for CC1M2.01 with CC1AB2.0 Kategorie: C-Control I V1.2/2.0 (von Windt H.J. - 19.11.2004 18:17)
'----------------------------------------------------------------------------------------------------'
'***********************************************************************'
'*                         WINDT SYSTEMS                               *'
'* COMPASS CMPS03 16 BIT BEARING READ v1.3 for CC1M2.01 with CC1AB2.0  *'
'*                           H.J. WINDT                                *'
'*                             2004                                    *'
'***********************************************************************'
'----------------------------------------------------------------------------------------------------'
'This program reads the 16 bit bearing data from the MILFORD Magnetic Compass Module (CMPS03) #5-124 '
'via the I2C bus and displays the data on the lcd as Bearing and Direction'
'Bearing range is from 0 to 3599, this represents 0º to 359.9º'
'Feel free to use and share this software!'
'----------------------------------------------------------------------------------------------------'
'*************** INS and OUTS ***************'
define lcd_light_off port[16]
'*******************************************'
'**************** VARIABLES ****************'
define config byte[1]
define iic_error bit[7]

define iic_high_byte byte[3]
define iic_low_byte byte[4]
define iic_word word[2]
'*******************************************'
'**************** CONSTANTS ****************'

'*******************************************'
'****************** SETUP ******************'
print"#ON_LCD#";
print"#INIT#";
print"#CLR#";
print"#OFF#";
lcd_light_off = 0
'*******************************************'
'***************** PROGRAM *****************'
#start
gosub compass_read
print"#ON_LCD#";
print"#L101#";
print"Bearing = ";
print iic_word / 10;
put &h2e '.'
print iic_word - (iic_word / 10 * 10);
put &hdf 'º'
print"     ";
print"#L201#";
print"Direct. = ";
gosub print_direction
print"  ";
print"#OFF#";
goto start
'*******************************************'
'*************** SUBROUTINES ***************'
#compass_read
print"#ON_IIC#";
print"#START#";
put &b11000000    'CMPS03 ADDRESS AND WRITE'
put &b00000010    'CMPS03 START REGISTER FOR 16 BIT COMPASS DATA'
print"#STOP#";
print"#START#";
put &b11000001    'CMPS03 ADDRESS AND READ'
get iic_high_byte 'READ HIGH BYTE'
get iic_low_byte  'READ LOW BYTE'
print"#STOP#";
print"#OFF#";
gosub check_for_iic_error 'CHECK FOR I2C ERROR'
if iic_error = 1 then goto compass_read
if iic_word < 0 or iic_word > 3599 then goto compass_read 'CHECK FOR CMPS03 DATA ERROR'
return

#check_for_iic_error
print"#ON_CONFIG#";
get config
if iic_error = 0 then goto pass_iic_error_clear
iic_error = 0
put config
iic_error = 1
#pass_iic_error_clear
print"#OFF#";
return

#print_direction
if iic_word > 112 then goto pass_n
print"N";
return
#pass_n
if iic_word > 337 then goto pass_nne
print"NNE";
return
#pass_nne
if iic_word > 562 then goto pass_ne
print"NE ";
return
#pass_ne
if iic_word > 787 then goto pass_ene
print"ENE";
return
#pass_ene
if iic_word > 1012 then goto pass_e
print"E";
return
#pass_e
if iic_word > 1237 then goto pass_ese
print"ESE";
return
#pass_ese
if iic_word > 1462 then goto pass_se
print"SE";
return
#pass_se
if iic_word > 1687 then goto pass_sse
print"SSE";
return
#pass_sse
if iic_word > 1912 then goto pass_s
print"S";
return
#pass_s
if iic_word > 2137 then goto pass_ssw
print"SSW";
return
#pass_ssw
if iic_word > 2362 then goto pass_sw
print"SW";
return
#pass_sw
if iic_word > 2587 then goto pass_wsw
print"WSW";
return
#pass_wsw
if iic_word > 2812 then goto pass_w
print"W";
return
#pass_w
if iic_word > 3037 then goto pass_wnw
print"WNW";
return
#pass_wnw
if iic_word > 3262 then goto pass_nw
print"NW";
return
#pass_nw
if iic_word > 3487 then goto pass_nnw
print"NNW";
return
#pass_nnw
print"N";
return
'*******************************************'
'****************** DATA *******************'

'*******************************************'



 Antwort schreiben

Bisherige Antworten: