You are on page 1of 6

MAIN PROGRAM

START

INITIAL SETUP
Start

Initial Setup

include P18F14K22.INC

MAIN Set Configuration Bits

Is Button Pressed?

Yes

Set X, Y & Z Data Values To Show Current Mode Declare Variables Output Mode Data to LED’s

No Get X, Y & Z Data from Accelerometer

Line or dot mode? Line Run Line Conversion

Dot

Run Dot Conversion

Get X & Y Data from Accelerometer

Define Definitions

Adjust Mode Change Threshold Depending On Current Sensitivity

Setup Internal Modules (Oscillator, Ports, USART, I2C)

Output Converted X, Y & Z Data to LED’s

Is Y Value Below Threshold No Adjust Sensitivity Increase Threshold Depending On Current Sensitivity

Yes

Go to Change Mode Function

Setup Peripherals (Port Expander, Accelerometer)

Return

Is X Value Below Threshold No Adjust Sensitivity Decrease Threshold Depending On Current Sensitivity

Yes

Go to Increase Sensitivity Function

Is X Value Above Threshold No

Yes

Go to Decrease Sensitivity Function

Goto Start

Get X Data
Start

Get Y Data
Start

Get Z Data
Start

Send X Data
Start

Send Y Data
Start

Send Z Data
Start

Load Accelerometer Address And X Register Address

Load Accelerometer Address And Y Register Address

Load Accelerometer Address And Z Register Address

Load Port Expander Address, PortA Register Address &Data to Send

Load Port Expander Address, PortA Register Address &Data to Send

Request I2c Data (call I2Crx)

Request I2c Data (call I2Crx)

Request I2c Data (call I2Crx)

Send I2C Data (call I2Ctx)

Send I2C Data (call I2Ctx)

Load Data to Send

Move Returned Data To Xraw

Move Returned Data To Yraw

Move Returned Data To Zraw

Return

Return

Yes Convert from 2's Compliment to Standard Format Convert from 2's Compliment to Standard Format Convert from 2's Compliment to Standard Format

Was Same Data Sent Previousley

No

Return

Return

Return

Return

Shift Data Out To Shift Register

I2Ctx
Start

I2Crx
Start

I2C Idle routine
Start

Generate I2C start condition idle Send Device Address and write bit idle Send Register Address idle

Generate I2C start condition idle Send Device Address and write bit idle Send Register Address idle Generate repeated start condition idle

Send Device Address and read bit Idle Enable receive mode. Idle No Transfere received data to i2cdat Idle Generate Stop Condition Are any status bits still set? Is transmit in progress?

Transmit Data

idle Generate stop condition Idle Return

Idle Return Return

Increase Sensitity
Start

Decrease Sensitity
Start

Is Button Still Pressed

No

Return

Is Button Still Pressed

No

Return

Yes Output Data to X led row to show Tilt has been recognised

Yes Output Data to X led row to show Tilt has been recognised

No

No

Has board returned to level? Yes If in 8g set to 4g, If in 4g set to 2g

Has board returned to level? Yes If in 2g set to 4g, If in 4g set to 8g

Clear Data on X led row to show mode has changed

Clear Data on X led row to show mode has changed

Update Accelerometer Settings

Update Accelerometer Settings

Change Mode
Start

Update Accelerometer Settings
Start

Is Button Still Pressed

No

Return

Set Accelerometer To Standby

Yes Output Data to Y led row to show Tilt has been recognised Should 2g mode be active? No Should 4g mode be active? Yes Set to 2g Mode

No

Has board returned to level? Yes If in 2g set to 4g, If in 4g set to 8g

Yes

Set to 4g Mode

No Should 8g mode be active? Set Accelerometer To Active

Yes

Set to 8g Mode

Clear Data on X led row to show mode has changed

Goto Main

Flip function
Start

Move data to temporary variable and clear data

Is bit:0 of temporary variable set No Is bit:1 of temporary variable set No Is bit:2 of temporary variable set No Is bit:3 of temporary variable set No Is bit:4 of temporary variable set No Is bit:5 of temporary variable set No Is bit:6 of temporary variable set No Is bit:7 of temporary variable set No Return

Yes

Set bit 7 of data

Yes

Set bit 6 of data

Yes

Set bit 5 of data

Yes

Set bit 4 of data

Yes

Set bit 3 of data

Yes

Set bit 2 of data

Yes

Set bit 1 of data

Yes

Set bit 0 of data

Dot conversion
Start

Convert data to dot pattern
Start

Load xraw to be converted

Clear output

Convert data to dot pattern

Output = 00000001 Then Return

Yes

Is data less than 0x18

No

Move converted result to xoutput. Load yraw to be converted. Output = 00000010 Then Return Convert data to dot pattern Yes

No

Is data less than 0x28

Yes

Output = 00000011 Then Return

Is data less than 0x38

No

No

Is data less than 0x48

Yes

Output = 00000110 Then Return

Move converted result to youtput. Load zraw to be converted.

Output = 00000100 Then Return

Yes

Is data less than 0x58

No

No Convert data to dot pattern Output = 00001000 Then Return Move converted result to zoutput. No Yes Is data less than 0x78

Is data less than 0x68

Yes

Output = 00001100 Then Return

No

Is data less than 0x88

Yes

Output = 00011000 Then Return

Return

Output = 00010000 Then Return

Yes

Is data less than 0x98

No

No

Is data less than 0xa8

Yes

Output = 00110000 Then Return

Output = 00100000 Then Return

Yes

Is data less than 0xb8

No

No

Is data less than 0xc8

Yes

Output = 01100000 Then Return

Output = 01000000 Then Return

Yes

Is data less than 0xd8

No

Output = 10000000 Then Return

No

Is data less than 0xe8

Yes

Output = 11000000 Then Return

line conversion
Start

Convert data to line pattern

Clear output

Start

Load xraw to be converted

Output = 11111111 Then Return

Yes

Is data less than 0x08

No

Convert data to line pattern

No

Is data less than 0x18

Yes

Output = 11111110 Then Return

Move converted result to xoutput. Load yraw to be converted.

Output = 11111100 Then Return

Yes

Is data less than 0x28

No

No Convert data to line pattern

Is data less than 0x38

Yes

Output = 11111000 Then Return

Output = 11110000 Then Return

Yes

Is data less than 0x48

No

Move converted result to youtput. Load zraw to be converted. Output = 11000000 Then Return

No

Is data less than 0x58

Yes

Output = 11100000 Then Return

Convert data to line pattern

Yes

Is data less than 0x68

No

No Call flip function to reverse pattern

Is data less than 0x78

Yes

Output = 10000000 Then Return

Output = 00000000 Then Return

Yes

Is data less than 0x88

No

Move flipped result to zoutput

No

Is data less than 0x98

Yes

Output = 10000000 Then Return

Return

Output = 11000000 Then Return

Yes

Is data less than 0xa8

No

No

Is data less than 0xb8

Yes

Output = 11100000 Then Return

Output = 11110000 Then Return

Yes

Is data less than 0xc8

No

No

Is data less than 0xd8

Yes

Output = 11111000 Then Return

Output = 11111100 Then Return

Yes

Is data less than 0xe8

No

Output = 11111111 Then Return

No

Is data less than 0xf8

Yes

Output = 11111110 Then Return