Subversion Repositories MK3Mag

Compare Revisions

Ignore whitespace Rev 64 → Rev 65

/tags/V0.22c/Compass.pnproj
0,0 → 1,0
<Project name="avr_ctrl"><File path="uart.h"></File><File path="main.c"></File><File path="main.h"></File><File path="makefile"></File><File path="uart.c"></File><File path="timer0.c"></File><File path="timer0.h"></File><File path="analog.h"></File><File path="analog.c"></File><File path="twislave.c"></File><File path="twislave.h"></File><File path="menu.c"></File></Project>
/tags/V0.22c/Compassl.pnps
0,0 → 1,0
<pd><ViewState><e p="avr_ctrl" x="true"></e></ViewState></pd>
/tags/V0.22c/Hex-Files/BootLoader_MEGA168_8MHZ_V0.2.hex
0,0 → 1,61
:1038000011241FBECFEFD4E0DEBFCDBF11E0A0E09A
:10381000B1E0EEEAFBE302C005900D92A030B107E3
:10382000D9F711E0A0E0B1E001C01D92A238B107C4
:10383000E1F70C943B1C0C941D1C0895982F80916B
:10384000C00085FFFCCF9093C60008958091C00012
:103850008823E4F78091C600992708958DE40E949B
:103860001E1C8BE40E941E1C82E40E941E1C8CE421
:103870000E941E1C0895CFEFD4E0DEBFCDBFE0E074
:10388000F0E004917F01992494BE98E10FB6F8947A
:1038900090936000109260000FBE9092C50080E18E
:1038A0008093C4008091C00082608093C000909398
:1038B000C10086E08093C200EF01192D8091C00005
:1038C00087FF0DC0113031F48091C6008A3A89F12A
:1038D00010E005C08091C6008B3109F411E0CE01E3
:1038E00021968436910500F10F3F41F0002331F01D
:1038F000E0910001F0910101099516C08AE00E9453
:103900001E1C8DE00E941E1C86E50E941E1C80E38A
:103910000E941E1C8EE20E941E1C82E30E941E1C3E
:103920008AE30E941E1C05C080E29EE40197F1F725
:10393000C5CF0E942E1C0E94261C813611F489E5F9
:1039400033C1813471F40E94261CE82EFF24FE2C22
:10395000EE240E94261C9927E82AF92AF694E79477
:10396000F1C0823641F489E50E941E1C80E00E946D
:103970001E1C80E819C1823409F075C00E94261C03
:103980000E94261CD82E0E94261C082FB2E0AB2EC7
:10399000B1E0BB2E10E0E5010894A11CB11C1D157F
:1039A00018F40E94261C01C08FEF88831F5F17FF49
:1039B000F2CF38E7931609F0D4C0063409F03DC0C1
:1039C0008FEFE81687E3F80608F033C0CD2DA70186
:1039D00066277727440F551F661F771F6A017B01F3
:1039E000A2E0B1E011E08D9199272D913327322F7C
:1039F0002227822B932B0C01FA0110935700E89594
:103A000011244E5F5F4F6F4F7F4FC25061F785E0CB
:103A1000F60180935700E89507B600FCFDCF81E1E1
:103A200080935700E89576956795579547957A0165
:103A300089C080E00E941E1C85C0053409F082C048
:103A4000F7012D2DA2E0B1E0E1BD8F2F992782BDB6
:103A50008D9180BD3196FA9AF99AF999FECF21504D
:103A600099F77F016FC0873609F03DC00E94261C80
:103A70000E94261CC82F0E94261C863419F5C701F7
:103A8000AA27BB276C017D01CC0CDD1CEE1CFF1CA2
:103A9000F60105911491802F0E941E1C812F9927F9
:103AA0000E941E1C82E090E0A0E0B0E0C80ED91E8B
:103AB000EA1EFB1EC25061F7F694E794D794C794B0
:103AC000760139CF853409F036CFE1BC8F2D9927A7
:103AD00082BDF89A0894E11CF11C80B50E941E1C5E
:103AE000C15099F728CF853601F598E7991651F519
:103AF00080E090E0A0E0B0E023E0FC0120935700DC
:103B0000E89507B600FCFDCF80589F4FAF4FBF4FE1
:103B10008F3F37E3930730E0A30730E0B30768F344
:103B200081E180935700E8950DC0853469F488E100
:103B300090E02CE00FB6F894A895809360000FBE3B
:103B4000209360008DE030C08035E1F38C34D1F3F8
:103B5000803711F483E528C0843729F488E70E9470
:103B60001E1C80E021C0843521F40E94261C982E62
:103B7000E9CF8B3109F4DDCE8A3A09F4DACE863505
:103B800029F480E30E941E1C82E30EC0833741F4B7
:103B900086E00E941E1C84E90E941E1C8EE104C067
:0E3BA0008B3109F4C8CE8FE30E941E1CC4CEE8
:0400000300003800C1
:00000001FF
/tags/V0.22c/Hex-Files/MK3Mag_MEGA168_V0_22c_SVN62.hex
0,0 → 1,804
:100000000C94B8010C94D3010C94D3010C94D3013B
:100010000C94D3010C94D3010C94D3010C94D30110
:100020000C94D3010C94D3010C94D3010C94D30100
:100030000C94D3010C94D3010C94D3010C94D301F0
:100040000C94B30E0C94D3010C944F0A0C94D3016E
:100050000C94160A0C94D3010C94D3010C94D30184
:100060000C94C10F0C94D30107BAA57A2C3BDA90FB
:10007000C5BC8BFC663CFD10F8BD4D83923DB63A85
:100080009EBE5BBFCA3FC90FDA000829573F9F2DAC
:1000900049CBA5310F76C73493F27E37D00D013AA4
:1000A000B60B613D2AAAAB3F0000003F8000000074
:1000B000083B3BD74ABC846E023D2FC1FEBD9A313E
:1000C000743DDA3D83BE117FC73E4CBBE5BEAAAA94
:1000D0006C3F800000004D61676E657420582020E1
:1000E0002020202020204D61676E6574205920203B
:1000F0002020202020204D61676E6574205A20202A
:100100002020202020205261774D61676E65742089
:100110005820202020205261774D61676E65742041
:100120005920202020205261774D61676E65742030
:100130005A20202020204174746974756465204E13
:1001400069636B2020204174746974756465205262
:100150006F6C6C2020204D61676E65742058204FB5
:100160006666736574204D61676E65742058205211
:10017000616E676520204D61676E65742059204F60
:100180006666736574204D61676E657420592052F0
:10019000616E676520204D61676E6574205A204F3F
:1001A0006666736574204D61676E6574205A2052CF
:1001B000616E6765202043616C73746174652020F3
:1001C00020202020202048656164696E672020205F
:1001D00020202020202055736572302020202020F0
:1001E00020202020202055736572312020202020DF
:1001F0002020202020204163632058202020202020
:10020000202020202020416363205920202020200E
:10021000202020202020416363205A2020202020FD
:100220002020202020205261774163632058202025
:100230002020202020205261774163632059202014
:10024000202020202020526177416363205A202003
:100250002020202020204163632058204F666673B1
:100260006574202020204163632059204F66667307
:10027000657420202020416363205A204F666673F6
:1002800065742020202048656164696E67205820CD
:1002900020202020202048656164696E6720592055
:1002A00020202020202041747469747564652053D7
:1002B0006F7572636520493243204572726F7220F8
:1002C000202020202020493243204F6B61792020BC
:1002D0002020202020205B25695D005B25695D00D2
:1002E0002B2B2020204D4B334D41472020202B2B02
:1002F000200020562025642E2564256300204143DC
:100300004320537570706F727420200020202020CD
:100310002020202020202020200028632920427532
:1003200073732C204275736B6572202020004D6121
:10033000676E65742053656E736F72733A20005850
:100340003A252B3464202020202020202020005912
:100350003A252B3464202020202020202020005A01
:100360003A252B346420202020202020202000004B
:1003700011241FBECFEFD4E0DEBFCDBF11E0A0E05F
:10038000B1E0E8E4F1E302C005900D92AE3DB107A3
:10039000D9F713E0AEEDB1E001C01D92AB35B10766
:1003A000E1F70C94F9070C9400000F931F93CF937F
:1003B000DF9340915002509151028091310290910F
:1003C0003202481B590B5093590240935802C09176
:1003D0003502D091360280912F0290913002C81BD5
:1003E000D90BD0933402C093330200915402109180
:1003F00055028091560290915702081B190B1093D9
:100400005302009352022091370230913802211595
:10041000310509F4B1C08091390290913A02481B2C
:10042000590BCA01AA2797FDA095BA2F5AE0880F49
:10043000991FAA1FBB1F5A95D1F7442737FD409536
:10044000542FBC01CD010E946B183093F30120930F
:10045000F20120913B0230913C022115310509F453
:1004600082C080913D0290913E02C81BD90BCE0103
:10047000AA2797FDA095BA2F4AE0880F991FAA1FB7
:10048000BB1F4A95D1F7442737FD4095542FBC0137
:10049000CD010E946B183093F1012093F0018091FF
:1004A000410290914202081B190BC801AA2797FD2F
:1004B000A095BA2F2AE0880F991FAA1FBB1F2A9563
:1004C000D1F720913F0230914002442737FD4095FB
:1004D000542FBC01CD010E946B183093EF01209383
:1004E000EE0180912102882309F4CCC0C091EC0177
:1004F000D091ED018091450290914602C81BD90B25
:10050000D093E701C093E6014091EA015091EB01DD
:100510008091490290914A02481B590B5093E50182
:100520004093E40180914D0290914E022091E801A8
:100530003091E901821B930B9093E3018093E201D8
:1005400049385105F4F080E293E09093E101809303
:10055000E001C938D1051CF180E293E09093DF01FE
:100560008093DE018FC03093F1012093F00130932E
:10057000EF012093EE01B5CF3093F3012093F20108
:1005800068CF8FEF483758070CF046C080EE9CEFDD
:100590009093E1018093E001C938D105ECF68FEF2B
:1005A000C837D8071CF480EE9CEFD8CFCE01AA271D
:1005B00097FDA095BA2FBC01CD010E946816DC0101
:1005C000CB0120E030E04AE053E4BC01CD010E94C1
:1005D0000516DC01CB01BC01CD010E949215DC01A6
:1005E000CB0120E030E041EE54E4BC01CD010E949B
:1005F0005417DC01CB012BED3FE049E450E4BC0192
:10060000CD010E940516DC01CB01BC01CD010E9489
:100610004B16DC01CB01A2CFCA01AA2797FDA095FA
:10062000BA2FBC01CD010E946816DC01CB0120E08D
:1006300030E04AE053E4BC01CD010E940516DC0124
:10064000CB01BC01CD010E949215DC01CB0120E061
:1006500030E041EE54E4BC01CD010E945417DC01AE
:10066000CB012BED3FE049E450E4BC01CD010E94F9
:100670000516DC01CB01BC01CD010E944B16DC014B
:10068000CB0163CFDF91CF911F910F9108952F92EE
:100690003F924F925F926F927F928F929F92AF9212
:1006A000BF92CF92DF92EF92FF920F931F93CF935F
:1006B000DF93CDB7DEB724970FB6F894DEBF0FBE39
:1006C000CDBF0F2EF0E02F2EF0E03F2EF0E04F2EAA
:1006D000F0E05F2EF02D8201710129823A824B8277
:1006E0005C828091F4019091F5010E941A0F882399
:1006F00089F080914F02813009F456C18BB190E8A6
:1007000089278BB986E990E00E94110F9093F5013B
:100710008093F40180914F028130A9F02FEF3FEFD9
:10072000F894C90188599E4F815D924028F4309316
:1007300001012093000160C18FEF9FEF90930101B1
:100740008093000159C1809102019927009709F017
:1007500005C18091F2019091F301AA2797FDA09520
:10076000BA2FBC01CD010E9468167B018C018091DB
:10077000F0019091F101AA2797FDA095BA2FBC0135
:10078000CD010E9468161B012C018091EE01909111
:10079000EF01AA2797FDA095BA2FBC01CD010E94B9
:1007A000681669837A838B839C83809103019927E0
:1007B0008130910509F4FAC0823091050CF40EC124
:1007C000029709F402C188249924C401AA2797FD3D
:1007D000A095BA2FBC01CD010E946816DC01CB01A7
:1007E0002BED3FE049E450E4BC01CD010E945417D9
:1007F000DC01CB0120E030E041EE54E4BC01CD014E
:100800000E9405165B016C01C401AA2797FDA09503
:10081000BA2FBC01CD010E946816DC01CB012BED83
:100820003FE049E450E4BC01CD010E945417DC01D3
:10083000CB0120E030E041EE54E4BC01CD010E9448
:1008400005163B014C01C601B5010E94FF15DC01F4
:10085000CB01A8019701BC01CD010E9454177B0177
:100860008C01C601B5010E949C17DC01CB012981D6
:100870003A814B815C81BC01CD010E945417DC019F
:10088000CB019C01AD01C801B7010E944F155B016E
:100890006C01C401B3010E94FF15DC01CB01A20170
:1008A0009101BC01CD010E9454177B018C01C40150
:1008B000B3010E949C17DC01CB0129813A814B8155
:1008C0005C81BC01CD010E945417DC01CB019C016D
:1008D000AD01C801B7010E9450157B018C01C60112
:1008E000B5010E944B16DC01CB019093CE028093A0
:1008F000CD02C801B7010E944B16DC01CB019093D9
:10090000D0028093CF02A6019501C801B7010E94D1
:10091000CC15DC01CB0120E030E044E353E4BC0122
:10092000CD010E945417DC01CB012BED3FE049E4DF
:1009300050E4BC01CD010E940516DC01CB01BC01D5
:10094000CD010E944B16DC01CB019C0197FD39C003
:1009500088E691E0821B930B9C01E2CE019709F09F
:1009600024CF8091F0019091F101AA2797FDA095E5
:10097000BA2FBC01CD010E9468167B018C018091C9
:10098000F2019091F301AA2797FDA095BA2FBC011F
:10099000CD010E946816DC01CB011C012D0157FA24
:1009A000509457F85094F1CE5F9AACCEF894809161
:1009B0008D0290918E0280908F0290909002789498
:1009C00005CF309521953F4FABCE8091E0019091BE
:1009D000E1018090DE019090DF01F8CE892B09F0D3
:1009E000F2CEF894809140039091410380904203AD
:1009F000909043037894EACE789424960FB6F894B6
:100A0000DEBF0FBECDBFDF91CF911F910F91FF9041
:100A1000EF90DF90CF90BF90AF909F908F907F909E
:100A20006F905F904F903F902F9008951F93CF93BA
:100A3000DF9380913D03882309F44FC0182F1630AF
:100A400008F450C010E080910402882309F481C0AA
:100A50005F9AC0E0D0E0C330D10509F477C0C4305C
:100A6000D1050CF078C0C130D10509F4FBC0229744
:100A700009F05DC120915802309159028091F7012F
:100A80009091F801281739070CF428C18091F901D9
:100A90009091FA018217930724F43093FA0120937E
:100AA000F90120913302309134028091FB01909141
:100AB000FC012817390724F43093FC012093FB0133
:100AC0008091FD019091FE01821793070CF0C6C042
:100AD0003093FE012093FD01C1C0109193021630A6
:100AE00008F0B0CF112309F4AECF8091F4019091BA
:100AF000F5010E941A0F882329F48091F601181736
:100B000009F4F9C04091030240FFE1C08091040262
:100B1000882309F0E1C05F98842F99270196C12F9F
:100B2000DD279E012C0F3D1F821793070CF4DDC0BB
:100B3000109203028CED95E00E94110F9093F50145
:100B40008093F401C330D10509F089CF10920402DB
:100B5000EEC05F987ECFC430D10509F465C02597FB
:100B600009F0E5C08091F601181781F3E7E3F2E0A0
:100B70002091F9013091FA018091F7019091F801EB
:100B8000D901A81BB90BB0933802A0933702820F8A
:100B9000931F97FDA8C09595879590933A028093EF
:100BA00039022091FD013091FE018091FB0190916D
:100BB000FC01B901681B790B70933C0260933B0206
:100BC000820F931F97FD9CC09595879590933E0249
:100BD00080933D0220910102309102028091FF0139
:100BE00090910002A901481B590B50934002409379
:100BF0003F02820F931F97FD81C095958795909333
:100C0000420280934102A739B1053CF06739710572
:100C100024F0473951050CF075C0A0E0B0E089E13F
:100C2000182E0E94861892CF2091520230915302C2
:100C30008091FF01909100022817390724F4309326
:100C400000022093FF01809101029091020282171D
:100C5000930724F4309302022093010281E08093F1
:100C6000040265C020E137E23093F8012093F701D8
:100C700080EF98ED9093FA018093F9013093FC0195
:100C80002093FB019093FE018093FD0130930002BD
:100C90002093FF0190930202809301028091EC0166
:100CA0009091ED0190934602809345028091EA0174
:100CB0009091EB0190934A02809349028091E80160
:100CC0009091E90190934E0280934D023FCF809125
:100CD0000402882309F01FCF5F9A1ECF3093F801DA
:100CE0002093F701D3CE019656CF4F5F4093030276
:100CF00084E690E021CFC12FDD27ADCE01967DCFD8
:100D0000019662CF81E080934F025F98A0E0B0E04F
:100D100089E1182E0E948B1880ED97E00E94110F38
:100D20009093F5018093F401109203020FCF10937A
:100D3000F601DF91CF911F9108958091F20190917A
:100D4000F30190939802809397028091F001909123
:100D5000F10190939A02809399028091EE01909113
:100D6000EF0190939C0280939B0280915802909196
:100D7000590290939E0280939D028091330290913C
:100D800034029093A00280939F028091520290912E
:100D900053029093A2028093A10220910301822F1B
:100DA00099278130910509F43EC0823091050CF4F9
:100DB00058C0029709F448C08091390290913A02D4
:100DC0009093A8028093A7028091370290913802F5
:100DD0009093AA028093A90280913D0290913E02D5
:100DE0009093AC028093AB0280913B0290913C02C5
:100DF0009093AE028093AD028091410290914202A5
:100E00009093B0028093AF0280913F029091400294
:100E10009093B2028093B10280913D03882389F5BB
:100E2000809193022EC080918D0290918E029093BA
:100E3000A4028093A30280918F02909190029093DC
:100E4000A6028093A502B8CF8091E0019091E101C4
:100E50009093A4028093A3028091DE019091DF0120
:100E6000EECF892B09F0A8CF8091400390914103E8
:100E70009093A4028093A302809142039091430334
:100E8000DECF99279093B4028093B3028091000142
:100E9000909101019093B6028093B50280919102E6
:100EA00099279093B8028093B70280919202992774
:100EB0009093BA028093B9028091E6019091E70184
:100EC0009093BC028093BB028091E4019091E50174
:100ED0009093BE028093BD028091E2019091E30164
:100EE0009093C0028093BF028091EC019091ED013C
:100EF0009093C2028093C1028091EA019091EB012C
:100F00009093C4028093C3028091E8019091E9011B
:100F10009093C6028093C50280914502909146024B
:100F20009093C8028093C7028091490290914A022F
:100F30009093CA028093C90280914D0290914E0213
:100F40009093CC028093CB02822F99279093D20268
:100F50008093D102089580912102882369F4109230
:100F6000ED011092EC011092EB011092EA01109247
:100F7000E9011092E801089582E00E94320F209169
:100F8000EC013091ED01280F391F37FD29C035954F
:100F900027953093ED012093EC0183E00E94320FFE
:100FA0002091EA013091EB01280F391F37FD1EC057
:100FB000359527953093EB012093EA0186E00E9456
:100FC000320F2091E8013091E901280F391F37FDD8
:100FD0000AC0359527953093E9012093E8010895DB
:100FE0002F5F3F4FD4CF2F5F3F4FF3CF2F5F3F4F48
:100FF000DFCFCFEFD4E0DEBFCDBF3E98469A0E9450
:1010000024110E949D0E0E9450090E94470F0E94C9
:10101000830F789484E091E00E94810E83E591E053
:101020000E94810E80912102882309F01DC15F9AE0
:1010300088EC90E00E94110F9093F5018093F401E9
:10104000E7E3F2E0A0E0B0E089E1182E0E94861804
:101050001092930210923D0380E090E00E94110FE5
:10106000909307028093060280910502C82FDD2726
:10107000C130D10531F1C230D1050CF45BC0C230B2
:10108000D10509F472C0239709F486C080E090E08E
:101090000E94110F9093070280930602109205029E
:1010A0000E94650C80910A0290910B02892BE9F550
:1010B0000E940A0A80910502C82FDD27C130D105A0
:1010C000D1F680910602909107020E941A0F8823A0
:1010D00039F380E00E94320F9093510280935002C6
:1010E00081E00E94320F909581959F4F9093550219
:1010F0008093540287E00E94320F909336028093CF
:1011000035020E94AB07CE010E94110F9093070297
:101110008093060282E0809305020E94650C809114
:101120000A0290910B02892B19F20E94020A0E9476
:10113000280D9ACFCD2B09F0A9CF8091060290916E
:1011400007020E941A0F882309F4AACF8BB18F7966
:101150008BB982E090E00E94110F90930702809378
:10116000060281E080930502D8CF8091060290911B
:1011700007020E941A0F882309F492CF8BB1806670
:101180008BB9CE010E94110F909307028093060243
:1011900083E080930502C1CF8091060290910702FF
:1011A0000E941A0F882309F47BCF80E00E94320F3F
:1011B000909332028093310281E00E94320F909529
:1011C00081959F4F909357028093560287E00E942B
:1011D000320F9093300280932F020E94AB0781E080
:1011E00090E00E94110F90930702809306021092E4
:1011F00005020E94D50180919302882321F48091F9
:101200003D03882371F10E94160540912202442378
:1012100019F04150409322022091080230910902B6
:101220002115310531F021503040309309022093CF
:10123000080280910A0290910B02009729F0019711
:1012400090930B0280930A02232B09F029CF4423A9
:1012500009F026CF82E08093030181E080930201B0
:101260001FCF0E944703D1CF8BE791E00E94810EF0
:10127000DECECF93C82F8091C10083FF0DC0CA304E
:1012800039F08091C00085FFFCCFC093C60004C038
:101290008DE00E943909F5CF80E090E0CF9108956C
:1012A0001F93CF93CFB720E130E0F8948091C10035
:1012B0008F778093C1008091C1008F7B8093C100A4
:1012C00050985898519A5998832F99278093C50020
:1012D0002093C4008091C00082608093C000809100
:1012E000C2008F778093C2008091C2008F7B809371
:1012F000C2008091C2008F7D8093C2008091C200A5
:101300008F7E8093C2008091C200877F8093C2004D
:101310008091C1008B7F8093C1008091C200846066
:101320008093C2008091C20082608093C20080914D
:10133000C10080618093C1008091C100886080936A
:10134000C1008091C00087FF0CC08091C6008091D1
:10135000C000882334F48091C6008091C0008823A7
:10136000A4F38091C10080688093C1008091C10086
:1013700080648093C10080918A0190918B010E94CA
:10138000110F90933C0380933B0310921402109230
:101390001202109211021092100281E080938C01CF
:1013A0001092780286E18093790282E080937C0239
:1013B0001AE010937A0210927B02812F0E94390961
:1013C00083E40E94390980E50E9439098AE30E947A
:1013D000390986E50E94390980E30E9439098EE2C5
:1013E0000E94390982E30E94390982E30E94390987
:1013F00083E60E943909812F0E943909CFBFCF911E
:101400001F910895519A59988091C10088608093E6
:10141000C100089580918C018823E1F38091C1007F
:10142000877F8093C1005198599808951F920F9219
:101430000FB60F9211248F939F93EF93FF93809198
:101440008C018823A9F480911502909116020196CF
:10145000FC01E952FD4FE081ED3079F084369105D1
:1014600061F09093160280931502E093C6000EC0BF
:10147000109216021092150209C0109216021092D4
:10148000150281E080938C01E093C600FF91EF91FB
:101490009F918F910F900FBE0F901F9018951F92E4
:1014A0000F920FB60F9211242F933F934F935F9398
:1014B0008F939F93AF93BF93CF93DF93EF93FF935C
:1014C0005091C60080911402882309F073C04091A6
:1014D00019024423B9F45332E1F05D3011F1E42FE5
:1014E000FF27E65AFD4F50834F5F409319028091CA
:1014F000170290911802850F911D90931802809306
:10150000170258C04E3148F3809319028093140299
:1015100051C050935A0281E08093190283E290E017
:10152000ECCFA42FBB27A65ABD4FFD013297808177
:101530002091170230911802281B3109ED012197E3
:101540008881281B3109C9019F70909318028093EC
:1015500017020024880F991F001C880F991F001C78
:10156000892F902D982F935C2F733070235C80818E
:10157000891729F010921402109219021BC0888159
:101580008217C1F75C934F5F4093130281E0809311
:10159000140280915C02823579F788E190E02CE0BA
:1015A0000FB6F894A895809360000FBE209360005A
:1015B00010921902FF91EF91DF91CF91BF91AF91FE
:1015C0009F918F915F914F913F912F910F900FBEFF
:1015D0000F901F901895AC01A0E0B0E09D01A817F6
:1015E000B90748F4E7EDF2E08191280F311D11961B
:1015F000A417B507C8F33F70FD01E952FD4FC901BB
:101600000024880F991F001C880F991F001C892F28
:10161000902D835C80831196FD01E952FD4F2F735D
:101620003070822F835C8083A852BD4F8DE08C93F5
:1016300010928C018091D7028093C6000895BF92CA
:10164000CF92DF92EF92FF920F931F93CF93DF938E
:10165000CDB7DEB72C859D857E85BB2483E2809344
:10166000D7029F599093D8022093D90203E010E04B
:10167000772309F4ADC0CF84D88843E1E42EF12C60
:10168000EC0EFD1EA989BA897150109709F4A0C00B
:10169000109709F43CC0F601EB0DF11DB394908155
:1016A000119789F47723A1F1F70122E030E0E20EEF
:1016B000F31ED701C080D180E20EF31E0D90BC91C5
:1016C000A02DBB247150109719F1F601EB0DF11DFF
:1016D000B3944081119709F466C01097D1F0F601D8
:1016E000EB0DF11DB39460811197A1F4772391F074
:1016F000F7013296D701CD90DC9032E0E32EF12C49
:10170000EE0EFF1EA081B181BB24715003C090E09A
:1017100040E060E0F801E952FD4F892F86958695FB
:10172000835C80830F5F1F4FF801E952FD4F892FC3
:1017300099278370907082959295907F9827807FEB
:10174000982755279A01329522952F7023273F70AD
:101750002327822B835C80830F5F1F4FF801E952A0
:10176000FD4F4F705070440F551F440F551F862F6B
:1017700099270024880F991F001C880F991F001CAF
:10178000892F902D842B835C80830F5F1F4FF8017E
:10179000E952FD4F6F73635C60830F5F1F4F1097BB
:1017A00009F076CF15C0772309F4B3CFF701A2E093
:1017B000B0E0EA0EFB1ED701C080D18022E030E00D
:1017C000E20EF31E0D90BC91A02DBB24715085CF6D
:1017D000C8010E94EB0ADF91CF911F910F91FF90FA
:1017E000EF90DF90CF90BF900895A3E07A2F4091C3
:1017F0001302465009F45FC0E72FFF27E65AFD4F5A
:1018000080818D537F5FE72FFF27E65AFD4F2081B0
:101810002D537F5FE72FFF27E65AFD4F30813D5361
:101820007F5FE72FFF27E65AFD4F60816D537F5F93
:101830009927880F991F880F991F522F52955F7013
:10184000582B822F99278F70907082959295907F58
:101850009827807F9827232F26952695282B832F3E
:101860009927837090700024969587950794969594
:1018700087950794982F802D682B41504F3FD9F0C2
:10188000EA2FFF27E65AFD4F5083AF5F41504F3F8D
:1018900091F0EA2FFF27E65AFD4F2083AF5F4150BA
:1018A0004F3F49F0EA2FFF27E65AFD4F6083AF5FB5
:1018B000442309F0A1CF8DE592E09093120280932A
:1018C0001102A350A093100208958091140288235E
:1018D00009F408950E94F50B80915B02843609F4A7
:1018E00046C080915C0299278436910559F185366E
:1018F00091058CF48136910509F47FC082369105FB
:1019000009F488C010921202109211021092100273
:101910001092140208958836910509F45AC0893648
:1019200091050CF04CC08736910561F780910F024C
:10193000806180930F0280ED97E090930B0280937B
:101940000A02E0CFE0911102F091120290818AE048
:10195000989FC001112490938B0180938A01892B59
:1019600051F380910F02826080930F02E4CF809147
:101970005C0299278B36910521F08737910509F094
:10198000B0CFA0911102B091120288E0EDE8F2E030
:101990000D9001928A95E1F780910F028860809303
:1019A0000F0281E0809303018091940280930201F1
:1019B0008FEF90E0909309028093080292CF8637D0
:1019C000910509F09FCF80910F02816080930F02F3
:1019D000B2CFE0911102F0911202808190912D021C
:1019E000892B80932D02882311F010920C02809194
:1019F0000F02806280930F029ECFE0911102F0915E
:101A00001202808180930E0280910F028460809385
:101A10000F0291CFA0911102B09112028BE0E2E887
:101A2000F2E00D9001928A95E1F78091840281FFA6
:101A300007C0809193028F5F863039F080939302C4
:101A400080918B0280930D0276CF10929302F8CF93
:101A5000CF93DF93CDB7DEB760970FB6F894DEBFB4
:101A60000FBECDBF8091C10083FF42C180918C0128
:101A7000882309F43DC120910F0222FD53C08091BB
:101A80000D02882329F080918C01882309F0C4C0BD
:101A900080918A0190918B01892B09F084C021FFEC
:101AA00007C080918C01882309F0C9C020910F02E2
:101AB00025FF05C080918C01882309F0E0C024FF38
:101AC00005C080918C01882309F079C023FF05C0EF
:101AD00080918C01882309F086C020FF09C1809184
:101AE0008C01882309F404C18AE090E09F938F93CE
:101AF00088E792E09F938F9381E08F9383E08F93A9
:101B000086E58F930E941F0B80910F028E7F80933A
:101B10000F028DB79EB707960FB6F8949EBF0FBE03
:101B20008DBFE6C080918C01882309F4A8CF8091F5
:101B30000E02992782959295907F9827807F98270B
:101B40008A529F4F40E150E0BC01CE0101960E94B5
:101B5000351580E190E09F938F93CE0101969F937E
:101B60008F9381E090E09F938F938EE092E09F931C
:101B70008F9382E08F9383E08F9381E48F930E9411
:101B80001F0B8FEF80930E0280910F028B7F80934B
:101B90000F022DB73EB7255F3F4F0FB6F8943EBFFB
:101BA0000FBE2DBFA5C080913B0390913C030E94C6
:101BB0001A0F882309F075CF20910F0270CF8BE0A8
:101BC00090E09F938F9382E892E09F938F9381E0C0
:101BD0008F9383E08F9387E48F930E941F0B8091F4
:101BE0000F028F7E94CF82E090E09F938F9380E0EE
:101BF00091E09F938F9381E08F938F938BE48F93EA
:101C00000E941F0B80910F02877F80930F022DB7D8
:101C10003EB7295F3F4FC1CF81E090E09F938F9304
:101C20008DE092E09F938F9381E08F9383E08F9379
:101C300082E48F930E941F0B10920D026ACF0E94C4
:101C40009D0682E490E09F938F9385E992E09F93B5
:101C50008F9381E08F9383E08F9384E48F930E942E
:101C60001F0B80918A0190918B010E94110F90931C
:101C70003C0380933B0380910F028D7FC6CF0E946F
:101C8000301184E190E09F938F9390910C0284E156
:101C9000989FC001112483579E4F9F938F9381E09B
:101CA00090E09F938F938CE092E09F938F9382E0DC
:101CB0008F9381E08F9388E48F930E941F0B809114
:101CC0000C028F5F2DB73EB7255F3F4F0FB6F894DC
:101CD0003EBF0FBE2DBF843040F010920C028091A9
:101CE0000F028F7D80930F0203C080930C02F7CF09
:101CF00060960FB6F894DEBF0FBECDBFDF91CF91D7
:101D000008951F93CF93DF93EC0110E0888188231F
:101D100081F0A0E0B0E0AC0FBD1F1F5F8C910E946E
:101D20003909A12FBB27FE01EA0FFB1F8081882301
:101D300091F7DF91CF911F910895229A2A9884B547
:101D40008C7084BD85B5837385BD82E085BD16BC6E
:101D500080916E00897F80936E0080916E0081601B
:101D600080936E0008951F920F920FB60F92112468
:101D70002F933F934F938F939F9386B5855686BD40
:101D8000209100013091010137FD3FC080911F0279
:101D900090912002019641E08C37940728F12A9A0D
:101DA0001092200210921F0280911E02815051F564
:101DB0008AE080931E0280911C0290911D02019680
:101DC00090931D0280931C0280911A0290911B0235
:101DD000892BE9F080911A0290911B020197909350
:101DE0001B0280931A0213C09093200280931F025B
:101DF000265F3F4F82179307B8F22A9880911E0200
:101E00008150B1F280931E0202C02A98C9CF9F91DF
:101E10008F914F913F912F910F900FBE0F901F9078
:101E2000189520911C0230911D02280F391FC901FD
:101E30000197089520911C0230911D02821B930B83
:101E4000892F990F990B80780895CF93DF930E9483
:101E5000110FEC01CE010E941A0F8823D9F3DF91F4
:101E6000CF91089580937C0080917A008061809367
:101E70007A0080917A00806480937A0080917A0061
:101E800084FFFCCF8091780090917900089587B10C
:101E9000807F87B988B1807F88B98AB180668AB926
:101EA0008BB18F798BB910927C0080917A00877901
:101EB00080937A0080917A00876980937A001092EB
:101EC0007C0080917A00806480937A0088B18C6075
:101ED00088B980E29EE40197F1F782E00E94320F18
:101EE000895E934020F481E08093210208C083E062
:101EF0000E94320F895E9340B0F31092210288B1A4
:101F0000837F88B908959FB7F89484B18F7C84B992
:101F100085B1806385B987B18F7C87B988B18F7CA3
:101F200088B910922802109227021092240210926F
:101F3000290210922602109225021092230210927A
:101F40002A028FED8093BC008091BC008564809351
:101F5000BC0080E58093BA008091BC00856D8093C1
:101F6000BC001092460386E18093470382E0809391
:101F7000480383E08093490385EC8093BC009FBFB6
:101F800008951F920F920FB60F9211242F933F9333
:101F90008F939F93AF93BF93EF93FF938091B9007B
:101FA0009927887F907080389105A9F08138910534
:101FB0004CF0883A910509F44BC0883B9105A1F19A
:101FC00085EC33C1009709F180369105C9F78FEF91
:101FD00080932302F5CF3091BB00209123022F3F45
:101FE00009F452C09091230280912A02981778F048
:101FF0009091230280912A02981709F481C0809160
:1020000023028F5F80932302DBCF85ED0EC1809189
:102010002302E82FFF27E65BFC4F308380912B02E1
:10202000830F80932B02EBCFE0912702F0912802DF
:10203000309709F44AC090912402809129029817A0
:1020400008F043C080912402E80FF11D30810FC0D9
:102050001092240210922B02E0912702F0912802A4
:10206000309721F080912902823060F730E0809132
:102070002B02830F80932B02809124028F5F809329
:1020800024023093BB009CCF832F99278230910587
:1020900009F447C0833091050CF18330910509F4B0
:1020A00093C0049709F4B1C0109226021092250241
:1020B00010922A02109228021092270210922902EE
:1020C0001092230230932B027BCF909124028091B7
:1020D0002902981709F44DC030E0CECF019721F7BF
:1020E00086E493E0909328028093270284E0809313
:1020F0002902109226021092250210922A02E0CFA5
:1021000080912B02809580932B028317B1F18091EF
:10211000D3029091D40201969093D4028093D3027B
:102120006ECF84E593E0909328028093270286E0A7
:1021300080932902109226021092250210922A0200
:102140008091F2019091F301909355038093540391
:102150008091F0019091F101909357038093560381
:102160008091EE019091EF01909359038093580371
:10217000A7CF30912B0230957FCFA0912502B0914F
:1021800026021097B9F030E080912A02381728F023
:1021900011C0A0912502B0912602E32FFF27AE0FB8
:1021A000BF1FE65BFC4F80818C933F5F80912A02CA
:1021B000381778F38091D5029091D60201969093CA
:1021C000D6028093D5021BCF84E493E0909328023B
:1021D0008093270282E08093290280E493E0909329
:1021E00026028093250284E080932A0280910001D8
:1021F0009091010190934503809344031092030151
:1022000010920201209322025BCF8DE393E0909322
:1022100028028093270223E020932902909326022C
:102220008093250220932A024BCF8093BC00FF911C
:10223000EF91BF91AF919F918F913F912F910F900F
:102240000FBE0F901F901895579A5F98089590E2CF
:10225000EDE8F1E08FE49193815087FFFCCF089582
:102260001F93CF93DF9320912D0220FF08C0809110
:102270002E02882309F44FC0815080932E0221FF43
:102280000AC090912E028091DD01981709F49AC03E
:102290009F5F90932E02822F992780FF02C081FDBD
:1022A0003FC00E94271190912E028091DD01891775
:1022B00018F480932E02982F9A3018F581E18093BC
:1022C0002C02892F99279F938F9386ED92E09F93FD
:1022D0008F9381E08F930E94A0120F900F900F9028
:1022E0000F900F9090912E02C92FDD272097D9F0E3
:1022F000219709F46AC091509093DD0110922E024B
:10230000B0C080E180932C02892F99279F938F93EF
:102310008BED92E0DCCF8091DD0180932E02AFCF78
:1023200010922E02BECF10922C0280EE92E09F936C
:102330008F9311E01F930E94A01284E180932C02DE
:102340000F900F900F9083E690E09F938F9386E11C
:1023500090E09F938F93DF93CF9382EF92E09F93D0
:102360008F931F930E94A0128DB79EB709960FB648
:10237000F8949EBF0FBE8DBF809121028823E1F4A7
:1023800088E280932C028CE093E09F938F931F93BD
:102390000E94A0120F900F900F908CE380932C025C
:1023A0008AE193E09F938F9381E08F930E94A01224
:1023B0000F900F900F9055C088E280932C028DEF04
:1023C00092E0E3CF10922E0266CF10922C028EE2A2
:1023D00093E09F938F9311E01F930E94A01284E1DA
:1023E00080932C020F900F900F908091F2019091AA
:1023F000F3019F938F938FE393E09F938F931F93AA
:102400000E94A01288E280932C020F900F900F90F0
:102410000F900F908091F0019091F1019F938F9315
:102420008FE493E09F938F931F930E94A0128CE3FD
:1024300080932C020F900F900F900F900F9080912F
:10244000EE019091EF019F938F938FE593E09F931F
:102450008F931F930E94A0120F900F900F900F90D8
:102460000F9010922D02DF91CF911F910895982F18
:1024700080915A03813031F0892F0E943909282F29
:1024800033270CC080912C02E82FFF27E357FE4F23
:1024900090838F5F80932C0221E030E0C901089582
:1024A0000F931F93CF93DF938C01EB01672B71F098
:1024B000F80181918F010E943712219739F0F801BC
:1024C00081918F010E943712219791F7DF91CF916F
:1024D0001F910F9108950F931F93CF93DF938C015A
:1024E000EB01672B81F0F8010F5F1F4F84910E9471
:1024F0003712219741F0F8010F5F1F4F84910E941E
:102500003712219781F7DF91CF911F910F91089595
:10251000CF93C82F181634F480E20E943712C150AE
:102520001C16D4F3CF910895CF93C82F181634F406
:1025300080E30E943712C1501C16D4F3CF91089546
:102540002F923F924F925F926F927F928F929F92C3
:10255000AF92BF92CF92DF92EF92FF920F931F93B1
:10256000CF93DF93CDB7DEB7E0970FB6F894DEBF19
:102570000FBECDBF26968FAD26972896EEADFFAD48
:10258000289788249924540180935A0348E4C42E40
:10259000D12CCC0EDD1E7F01C701F7011491112350
:1025A00031F0153221F00894E11CF11CF6CFB7018F
:1025B000681B790B09F095C0112309F43DC20894FA
:1025C000E11CF11C1FA63FA4232C0FEF39A6F70135
:1025D0000894E11CF11C14911537C9F1812F806218
:1025E0008837A9F1103209F440C0133209F48DC0C4
:1025F0001A3209F479C01D3209F476C01B32C9F1D0
:102600001E32C9F1103309F48AC0812F81538930F9
:1026100008F07EC060E070E0CB01880F991F880F42
:10262000991F880F991F860F971F680F791F610FD9
:10263000711D60537040F7010894E11CF11C149166
:10264000812F80538A3040F3262E153739F630FE1D
:102650003DC0F60184E090E0C80ED91E80809180D4
:10266000A280B380103209F0C0CF89A5882309F079
:10267000AECF19A7ACCFF7010894E11CF11C14915F
:102680001A3209F451C060E070E014C0CB01880F29
:10269000991F880F991F880F991F860F971F680F22
:1026A000791F610F711D60537040F7010894E11CA0
:1026B000F11C1491812F80538A3040F3EFEF6F3F6C
:1026C0007E0714F46FEF7FEF062F86CFF60182E0CE
:1026D00090E0C80ED91E808191814C01AA24BB24B0
:1026E00081CF0E946B1268CF1A3251F4F60182E05A
:1026F00090E0C80ED91E208022200CF068CF2194D3
:1027000090E1392AEFED3E2262CF98E0392A5FCF7F
:102710001836C9F01C36D1F481E0382A58CF34FC81
:1027200056CFF0E23F2A53CFF60182E090E0C80E88
:10273000D91E608171819FEF6F3F790714F46FEFAD
:102740007FEF062F44CF24E0322A41CF133609F41D
:102750004DC1143409F41FC1143609F41CC11936D3
:1027600009F419C11F3409F40FC11F3609F40CC153
:10277000103709F4F9C0133709F4B2C0153509F45C
:10278000ECC0153709F4E9C0183509F444C018370E
:1027900009F441C0112309F44FC1CE0101969DA750
:1027A0008CA7198381E0482E19A6632C7724042D69
:1027B0005FA4541857FC2DC029A5222331F10F5FC7
:1027C000050DC30180739070892B09F42FC122235A
:1027D00009F027C166FC1BC1C3018073907080970C
:1027E00009F410C1852D0E949412842D992787FD2C
:1027F0009095BC018CA59DA50E94501264FECCCE84
:10280000822D801B0E948812C7CE66FED9CF0E5F34
:10281000D7CF5524D1CFE0E1EEA733FE07C0811416
:102820009104A104B10411F0F0E43F2A19A60FA706
:1028300007FD02C02FED3222CE0189969DA78CA7FD
:1028400081149104A104B10419F49FA5992361F1A5
:10285000EEA54E2E55246624772418AA84149504D8
:10286000A604B70410F0F1E0F8ABC501B401A30170
:1028700092010E944918DC01CB01082F8A30F0F444
:10288000005DECA5FDA50293FDA7ECA7C501B40171
:10289000A30192010E94491849015A01F8A9FF2396
:1028A000E1F62EA5283079F0632C7724CE0101962D
:1028B000482EFCA54F1A28E2420E79CF095A183546
:1028C00001F70F7DDECF632C772463FEEFCF00335B
:1028D00069F380E3ECA5FDA58293FDA7ECA7E6CF05
:1028E000F60182E090E0C80ED91E0190F081E02D43
:1028F000FDA7ECA7EF2B81F4FE013196FDA7ECA715
:1029000088E289838EE6818385E78B838CE68C83DE
:102910008D8389E28E831F8207FD15C0802F992742
:1029200087FD9095AC0160E070E08CA59DA50E94AC
:102930004215009731F0482EFCA54F1A04150CF0F3
:1029400033CF402E31CFECA5FDA501900020E9F753
:1029500031974E2E2CA5421A27CF153511F481E060
:10296000382A9AE09EA762CFF60182E090E0C80E76
:10297000D91E808191814C01AA24BB2490E19EA79D
:10298000E0E43E2A18E752CF1F3411F4E1E03E2A7A
:10299000F8E0FEA74BCF143411F491E0392A30FE51
:1029A00018C0F60184E090E0C80ED91E80809180A6
:1029B000A280B380B7FE0AC0B094A0949094809493
:1029C000811C911CA11CB11C8DE289A79AE09EA7D5
:1029D0002ECFF60182E090E0C80ED91E8081918151
:1029E0004C01AA2497FCA094BA2CE4CFFE013196A6
:1029F000FDA7ECA7F60182E090E0C80ED91E808109
:102A00008983D0CE822D801B0E949412EBCE80E36E
:102A10008AA71BA762E070E0CE018A960E9450123E
:102A2000DBCE61E070E0CE018996F8CF822D801B6D
:102A30000E94881229A5CBCEE0960FB6F894DEBF8F
:102A40000FBECDBFDF91CF911F910F91FF90EF90FF
:102A5000DF90CF90BF90AF909F908F907F906F90BE
:102A60005F904F903F902F900895FB01DC0140FF55
:102A700005C002C005900D9205900D924250504045
:102A8000C8F70895FC014150504030F001900616FF
:102A9000D1F73197CF010895882799270895505885
:102AA000192EA4D101D054C1BA1762077307840745
:102AB0009507B1F188F40EF410940B2EBA2FA02DC7
:102AC000062E622F202D072E732F302D082E842FD7
:102AD000402D092E952F502DFF275523B9F0591B56
:102AE00049F0573E98F0469537952795A795F040C1
:102AF0005395C9F776F0BA0F621F731F841F30F425
:102B0000879577956795B795F040939517FA0F2EAF
:102B10000895BF1BBB27BA0B620B730B840BF6CF58
:102B2000DEF690C1AA2797FDA160AF939F775FE380
:102B300040E8613071058407950720F00E94C016B7
:102B4000AF9108959F938F937F936F93E8E6F0E0A2
:102B50000E94C3162F913F914F915F919F938F9346
:102B60007F936F939FE380E87727662750680E94E2
:102B700050150E94AF172F913F914F915F910E9486
:102B800054175FE349EC3FE02BED90680E9450152D
:102B9000AF91A0FD90680895552319F0992351F045
:102BA00018C09923A1F097FB6BED7FE089EC9FE3C0
:102BB00097F90895552359F02AF46BED7FE089E4E5
:102BC00090E40895662777278827992708950C941D
:102BD000C0161F93112797FD116057FD12600E94C8
:102BE00005160E94F11711FF08C02BED3FE049E4E4
:102BF00050E410FD50680E9450151F91089550E454
:102C000049EC3FE02BED6ED080C0F0D001D0A0C0E9
:102C1000552359F0992369F09F575F57951B33F45B
:102C200042F4903811F4915805C0AAC091589F3FC2
:102C300009F408C1BB27112462177307840730F415
:102C4000660F771F881FBB1F915098F311D00F920A
:102C50000FD00F920DD0A0E82617370748071B06A4
:102C600009F0A048BA2F602D7F918F91002408951C
:102C7000A0E80024621773078407B10528F0621BDF
:102C8000730B840BB1090A2A660F771F881FBB1FBD
:102C9000A69581F7089597FBB5D09F3738F0FEE9E8
:102CA000F91B982F872F762F6B2F05C0C8C09695DC
:102CB000879577956795F150D0F73EF4909580957C
:102CC000709561957F4F8F4F9F4F0895E89403C093
:102CD00097FB0EF4F3DFB62F672F782F892F9EE92D
:102CE000002436C05F77552319F444230AF048C006
:102CF0002F933F934F935F9388DF55274427A4D0AA
:102D00005F914F913F912F91CFC01F939F7750ECD0
:102D100049E43FE02BEDC4DE10E89F775FE349EC28
:102D20003FE02BED621773078407950720F050EC06
:102D300049E4B6DE112751D19068EAE8F0E023D0EB
:102D400091271F9108959A95BB0F661F771F881FC3
:102D500011249923A1F08823B2F79F3F59F0BB0FAC
:102D600048F421F4002011F460FF04C06F5F7F4F2E
:102D70008F4F9F4F881F9795879597F908955FC04C
:102D80009FEF80EC0895FF92EF92DF92CF92BF9277
:102D90006B017C01B59016D0B590BB2069F09F9374
:102DA0008F937F936F93B601C7010CD02F913F9102
:102DB0004F915F910E940516BF90CF90DF90EF90EA
:102DC000FF9008953DD102C09601A701EF93FF93B4
:102DD0000E945417FF91EF9133D1EF93FF930E941C
:102DE0005015FF91EF91BA9479F70895052E0926B1
:102DF00007FA440F551F5F3F79F0AA27A51708F07F
:102E000051E04795880F991F9F3F31F0BB27B917B5
:102E100008F091E0879508959F919F911124B0CF7C
:102E200097FB880F991F9F3F31F0BB27B91708F018
:102E300091E0879508959F919F911124A1CF6627D6
:102E40007727882799270895EBDFCF93DF93D52F36
:102E5000C42F55274427332722279923D9F09F379A
:102E6000C8F0F92F75DF592F482F372F262FF63945
:102E700068F411DF2DDFC030CD0721F0699379931D
:102E8000899399939058DF91CF910ACE99278827FB
:102E900077276627C030CD0721F0299339934993CE
:102EA0005993DF91CF9154CFA1DF01D051CF992316
:102EB00039F0552329F09F575F57950F13F49AF176
:102EC000C1CF91589F3FE1F3629FA12D0F92BB2785
:102ED000639FA00DB11DEE27729FA00DB11DEE1FC7
:102EE000AF93AA27649FB00DE11D739FB00DE11D44
:102EF000AA1F6627829FB00DE11DA61F5527749F4C
:102F0000E00DA11D551F839FE00DA11D561F849F3D
:102F1000A00D511D852F7A2F6E2F1F900F908823A3
:102F20001AF4939539F42CCF000C111CBB1F661FAB
:102F3000771F881F012808959F939F77993358F032
:102F400050E449EC3FE02BEDCDDE5FEB49EC3FE098
:102F50002BEDA6DDDADE5F9150789527089597FD79
:102F60000FCF992309F40895482F5ADFF92FFF57FF
:102F7000F5959F1B9F1BFF93EBDEFF92EF92DF9275
:102F8000CF92BF92AF929F928F926B017C0140587B
:102F900047953327222740685FE3B601C7014901FF
:102FA0005A010E9405169401A5010E9450154FEF89
:102FB0005FEF53D09B01AC0182169306A406B506C1
:102FC00061F78F909F90AF90BF90CF90DF90EF9080
:102FD000FF905F9125DF950FBBCE9B01AC010C9458
:102FE00054171F930F930027192F10789F775FE3D3
:102FF00040E8613071058407950718F000680E9469
:103000002518912B6F937F938F939F930E94ED17B9
:10301000E0EBF0E0B8DE5F914F913F912F910E947D
:103020005417002351F02BED3FE049EC5FE300E83B
:10303000902717FD50680E9450150F911F91089519
:10304000559145913591259108959B01AC019FE3E0
:1030500080E8772766270C940516E2DE992359F05D
:10306000AA27940FA51F43F032F04FEF50E09417BA
:10307000A50714F46DCEE3CE0EF006C000C09FEF9E
:1030800080E870E060E008959FE780E870E060E02D
:103090000895A1E21A2EAA1BBB1BFD010DC0AA1F99
:1030A000BB1FEE1FFF1FA217B307E407F50720F0B1
:1030B000A21BB30BE40BF50B661F771F881F991F2C
:1030C0001A9469F760957095809590959B01AC0175
:1030D000BD01CF01089597FB092E05260ED057FD9F
:1030E00004D0D7DF0AD0001C38F4509540953095B5
:1030F00021953F4F4F4F5F4F0895F6F7909580957C
:10310000709561957F4F8F4F9F4F089509D0019221
:103110001A94E1F7089501900BD01A94E1F70895FD
:10312000F999FECFB2BDA1BDF89A119600B40895E9
:10313000F999FECFB2BDA1BD00BC11960FB6F894AF
:08314000FA9AF99A0FBE0895F6
:10314800FFFF01020A0D74686520757365206F66BC
:10315800207468697320736F66747761726520697B
:1031680073206F6E6C79207065726D697474656414
:103178000A0D6F6E206F726967696E616C204D6908
:103188006B726F4B6F707465722D486172647761F2
:103198007265000A0D7777772E4D696B726F4B6FEA
:1031A800707465722E6465202863292048695379F4
:1031B8007374656D7320476D6248000A0A41434382
:1031C8002070726573656E740A00F4010148656CBD
:1031D8006C6F20576F726C640000000000000000E4
:1031E80000000000000000000000000000000000D7
:1031F80000000000000000000000000000000000C7
:1032080000000000000000000000000000000000B6
:0E3218000000000000000000000000000002A6
:00000001FF
/tags/V0.22c/License.txt
0,0 → 1,59
/*#######################################################################################
MK3Mag 3D-Magnet sensor
!!! THIS IS NOT FREE SOFTWARE !!!
#######################################################################################*/
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Copyright (c) 05.2008 Holger Buss
// + Thanks to Ilja Fähnrich (P_Latzhalter)
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
// + www.MikroKopter.com
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
// + mit unserer Zustimmung zulässig
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
// + AUSNAHME: Ein bei www.mikrokopter.de erworbener vorbestückter MK3Mag darf als Baugruppe auch in kommerziellen Systemen verbaut werden
// + Im Zweifelsfall bitte anfragen bei: info@mikrokopter.de
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
// + eindeutig als Ursprung verlinkt werden
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
// + Benutzung auf eigene Gefahr
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
// + mit unserer Zustimmung zulässig
/// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
// + this list of conditions and the following disclaimer.
// + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
// + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
// + from this software without specific prior written permission.
// + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
// + for non-commercial use (directly or indirectly)
// + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
// + with our written permission
// + Exception: A preassembled MK3Mag, purchased from www.mikrokopter.de may be used as a part of commercial systems
// + In case of doubt please contact: info@MikroKopter.de
// + * If sources or documentations are redistributet on other webpages, our webpage (http://www.MikroKopter.de) must be
// + clearly linked as origin
// + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// + POSSIBILITY OF SUCH DAMAGE.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/tags/V0.22c/analog.c
0,0 → 1,120
/*#######################################################################################
MK3Mag 3D-Magnet sensor
!!! THIS IS NOT FREE SOFTWARE !!!
#######################################################################################*/
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Copyright (c) 05.2008 Holger Buss
// + Thanks to Ilja Fähnrich (P_Latzhalter)
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
// + www.MikroKopter.com
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
// + mit unserer Zustimmung zulässig
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
// + AUSNAHME: Ein bei www.mikrokopter.de erworbener vorbestückter MK3Mag darf als Baugruppe auch in kommerziellen Systemen verbaut werden
// + Im Zweifelsfall bitte anfragen bei: info@mikrokopter.de
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
// + eindeutig als Ursprung verlinkt werden
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
// + Benutzung auf eigene Gefahr
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
// + mit unserer Zustimmung zulässig
/// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
// + this list of conditions and the following disclaimer.
// + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
// + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
// + from this software without specific prior written permission.
// + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
// + for non-commercial use (directly or indirectly)
// + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
// + with our written permission
// + Exception: A preassembled MK3Mag, purchased from www.mikrokopter.de may be used as a part of commercial systems
// + In case of doubt please contact: info@MikroKopter.de
// + * If sources or documentations are redistributet on other webpages, our webpage (http://www.MikroKopter.de) must be
// + clearly linked as origin
// + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// + POSSIBILITY OF SUCH DAMAGE.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include <util/delay.h>
#include "analog.h"
 
uint8_t AccPresent = 0;
 
void ADC_Init(void)
{
// The analog inputs have a VREF of 5V and a resolution of 10 bit (0...1024 counts)
// i.e. 4.88mV/Count
 
// set PortC 0,1,2,3 as input
DDRC &= ~((1<<DDC3)|(1<<DDC2)|(1<<DDC1)|(1<<DDC0));
// set PortC 0,1,2,3 as tri state
PORTC &= ~((1<<PORTC3)|(1<<PORTC2)|(1<<PORTC1)|(1<<PORTC0));
 
// port PD5 and PD6 control the current direction of the test coils of the sensors
DDRD |= ((1<<DDD5)|(1<<DDD6));
FLIP_LOW;
 
// disable internal reference voltage and right adjust bits in ADCW
ADMUX = 0x00;
// clear start conversion bit (ADSC = 0)
// disable ADC Auto Trigger Enable (ADATE = 0)
// disable interrupt (ADIE = 0)
ADCSRA &= ~((1<<ADSC)|(1<<ADATE)|(1<<ADIE));
// Enable ADC (ADEN = 1) with SYSCLK/128 (ADPS2 = 1, ADPS1 = 1, ADPS0 = 1) and clear ready flag (ADIF = 1)
ADCSRA |= ((1<<ADEN)|(1<<ADIF)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0));
ADMUX = 0x00; // select ADC0
ADCSRA |= (1<<ADSC); // start conversion
 
 
// Check if acceleration sensor is present
// The output of the LIS3L02AL (MK3MAG V1.0) and the LIS344ALH (MK3MAG V1.1) is Vdd/5 +/- 10% per 1g.
// The Vdd is 3.0V at this board therefore the sensitivity is 0.6V/g +/-10% that corresponds to 123 counts.
// The offsets at 0g is VDD/2 (1.5V) that is 307 counts.
// that yields to an ADC range of 184 to 430 counts.
 
// pullup PC2(AccX) and PC3 (AccY)
PORTC |= ((1<<PORTC3)|(1<<PORTC2));
_delay_ms(10.0);
// if ADC2 and ADC 3 is larger than 1000 counts (4.88V) no load is at the pins
if((ADC_GetValue(ADC2) > 1000) && (ADC_GetValue(ADC3) > 1000)) AccPresent = 0;
else AccPresent = 1;
// set port back to tristate
PORTC &= ~((1<<PORTC3)|(1<<PORTC2));
}
 
 
uint16_t ADC_GetValue(ADChannel_t channel)
{
uint16_t value = 0;
ADMUX = channel; // set muxer bits
ADCSRA |= (1<<ADIF); // clear ready-flag
ADCSRA |= (1<<ADSC); // start conversion
while (((ADCSRA & (1<<ADIF)) == 0)); // wait for end of conversion
value = ADCW; // read adc result
return(value);
}
 
 
 
/tags/V0.22c/analog.h
0,0 → 1,39
#ifndef _ANALOG_H_
#define _ANALOG_H_
 
#include <inttypes.h>
#include <avr/io.h>
 
#define FLIP_HIGH PORTD |= ((1<<PORTD5)|(1<<PORTD6))
#define FLIP_LOW PORTD &= ~((1<<PORTD5)|(1<<PORTD6))
 
typedef enum
{
ADC0 = 0,
ADC1 = 1,
ADC2 = 2,
ADC3 = 3,
ADC4 = 4,
ADC5 = 5,
ADC6 = 6,
ADC7 = 7,
REF1V1 = 14,
AGND = 15
} ADChannel_t;
 
 
#define MAG_X ADC0
#define MAG_Y ADC1
#define MAG_Z ADC7
#define ACC_X ADC2
#define ACC_Y ADC3
#define ACC_Z ADC6
 
 
extern uint8_t AccPresent;
 
void ADC_Init(void);
uint16_t ADC_GetValue(ADChannel_t channel);
 
#endif // _ANALOG_H_
 
/tags/V0.22c/led.c
0,0 → 1,73
/*#######################################################################################
MK3Mag 3D-Magnet sensor
!!! THIS IS NOT FREE SOFTWARE !!!
#######################################################################################*/
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Copyright (c) 05.2008 Holger Buss
// + Thanks to Ilja Fähnrich (P_Latzhalter)
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
// + www.MikroKopter.com
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
// + mit unserer Zustimmung zulässig
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
// + AUSNAHME: Ein bei www.mikrokopter.de erworbener vorbestückter MK3Mag darf als Baugruppe auch in kommerziellen Systemen verbaut werden
// + Im Zweifelsfall bitte anfragen bei: info@mikrokopter.de
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
// + eindeutig als Ursprung verlinkt werden
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
// + Benutzung auf eigene Gefahr
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
// + mit unserer Zustimmung zulässig
/// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
// + mit unserer Zustimmung zulässig
/// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
// + this list of conditions and the following disclaimer.
// + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
// + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
// + from this software without specific prior written permission.
// + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
// + for non-commercial use (directly or indirectly)
// + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
// + with our written permission
// + Exception: A preassembled MK3Mag, purchased from www.mikrokopter.de may be used as a part of commercial systems
// + In case of doubt please contact: info@MikroKopter.de
// + * If sources or documentations are redistributet on other webpages, our webpage (http://www.MikroKopter.de) must be
// + clearly linked as origin
// + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// + POSSIBILITY OF SUCH DAMAGE.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include "led.h"
 
 
void LED_Init(void)
{
// Set PD7 as output
DDRD |= (1<<DDD7);
// set port pon to GND
PORTD &= ~((1<<PORTD7));
}
 
/tags/V0.22c/led.h
0,0 → 1,12
#ifndef _LED_H_
#define _LED_H_
 
#include <avr/io.h>
 
#define LED_GRN_ON PORTD |= (1<<PORTD7)
#define LED_GRN_OFF PORTD &= ~(1<<PORTD7)
#define LED_GRN_TOGGLE PORTD ^= (1<<PORTD7)
 
void LED_Init(void);
 
#endif //_LED_H_
/tags/V0.22c/main.c
0,0 → 1,534
/*#######################################################################################
MK3Mag 3D-Magnet sensor
!!! THIS IS NOT FREE SOFTWARE !!!
#######################################################################################*/
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Copyright (c) 05.2008 Holger Buss
// + Thanks to Ilja Fähnrich (P_Latzhalter)
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
// + www.MikroKopter.com
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
// + mit unserer Zustimmung zulässig
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
// + AUSNAHME: Ein bei www.mikrokopter.de erworbener vorbestückter MK3Mag darf als Baugruppe auch in kommerziellen Systemen verbaut werden
// + Im Zweifelsfall bitte anfragen bei: info@mikrokopter.de
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
// + eindeutig als Ursprung verlinkt werden
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
// + Benutzung auf eigene Gefahr
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
// + this list of conditions and the following disclaimer.
// + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
// + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
// + from this software without specific prior written permission.
// + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
// + for non-commercial use (directly or indirectly)
// + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
// + with our written permission
// + Exception: A preassembled MK3Mag, purchased from www.mikrokopter.de may be used as a part of commercial systems
// + In case of doubt please contact: info@MikroKopter.de
// + * If sources or documentations are redistributet on other webpages, our webpage (http://www.MikroKopter.de) must be
// + clearly linked as origin
// + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// + POSSIBILITY OF SUCH DAMAGE.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include <avr/interrupt.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
 
#include "main.h"
#include "timer0.h"
#include "twislave.h"
#include "led.h"
#include "analog.h"
#include "uart.h"
 
#define CALIBRATION_VERSION 1
 
AttitudeSource_t AttitudeSource = ATTITUDE_SOURCE_ACC;
Orientation_t Orientation = ORIENTATION_FC;
 
uint16_t Led_Timer = 0;
 
typedef struct
{
int16_t Range;
int16_t Offset;
} Scaling_t;
 
typedef struct
{
Scaling_t MagX;
Scaling_t MagY;
Scaling_t MagZ;
Scaling_t AccX;
Scaling_t AccY;
Scaling_t AccZ;
unsigned char Version;
} Calibration_t;
 
Calibration_t eeCalibration EEMEM; // calibration data in EEProm
Calibration_t Calibration; // calibration data in RAM
 
// magnet sensor variable
int16_t RawMagnet1a, RawMagnet1b; // raw magnet sensor data
int16_t RawMagnet2a, RawMagnet2b;
int16_t RawMagnet3a, RawMagnet3b;
int16_t UncalMagX, UncalMagY, UncalMagZ; // sensor signal difference without Scaling
int16_t MagX = 0, MagY = 0, MagZ = 0; // rescaled magnetic field readings
 
// acceleration sensor variables
int16_t RawAccX = 0, RawAccY = 0, RawAccZ = 0; // raw acceleration readings
int16_t AccX = 0, AccY = 0, AccZ = 0; // rescaled acceleration readings
int16_t AccAttitudeNick = 0, AccAttitudeRoll = 0; // nick and roll angle from acc
 
int16_t Heading = -1; // the current compass heading in deg
 
 
void CalcFields(void)
{
UncalMagX = (RawMagnet1a - RawMagnet1b);
UncalMagY = (RawMagnet3a - RawMagnet3b);
UncalMagZ = (RawMagnet2a - RawMagnet2b);
if(Calibration.MagX.Range != 0) MagX = (1024L * (int32_t)(UncalMagX - Calibration.MagX.Offset)) / (Calibration.MagX.Range);
else MagX = 0;
if(Calibration.MagY.Range != 0) MagY = (1024L * (int32_t)(UncalMagY - Calibration.MagY.Offset)) / (Calibration.MagY.Range);
else MagY = 0;
if(Calibration.MagY.Range != 0) MagZ = (1024L * (int32_t)(UncalMagZ - Calibration.MagZ.Offset)) / (Calibration.MagZ.Range);
else MagZ = 0;
if(AccPresent)
{
AccX = (RawAccX - Calibration.AccX.Offset);
AccY = (RawAccY - Calibration.AccY.Offset);
AccZ = (Calibration.AccZ.Offset - RawAccZ);
#if (BOARD == 10) // the hardware 1.0 has the LIS3L02AL
// acc mode assumes orientation like FC
if(AccX > 136) AccAttitudeNick = -800;
else
if(AccX < -136) AccAttitudeNick = 800;
else AccAttitudeNick = (int16_t)(-1800.0 * asin((double) AccX / 138.0) / M_PI);
 
 
if(AccY > 136) AccAttitudeRoll = 800;
else
if(AccY < -136) AccAttitudeRoll = -800;
else AccAttitudeRoll = (int16_t)( 1800.0 * asin((double) AccY / 138.0) / M_PI);
 
#else // the hardware 1.1 has the LIS344ALH with a different axis definition (X -> -Y, Y -> X, Z -> Z)
// acc mode assumes orientation like FC
if(AccY > 136) AccAttitudeNick = 800;
else
if(AccY < -136) AccAttitudeNick = -800;
else AccAttitudeNick = (int16_t)( 1800.0 * asin((double) AccY / 138.0) / M_PI);
 
 
if(AccX > 136) AccAttitudeRoll = 800;
else
if(AccX < -136) AccAttitudeRoll = -800;
else AccAttitudeRoll = (int16_t)( 1800.0 * asin((double) AccX / 138.0) / M_PI);
#endif
}
}
 
 
void CalcHeading(void)
{
double nick_rad, roll_rad, Cx = 0, Cy = 0, Cz = 0, Hx = 0, Hy = 0;
int16_t nick, roll;
int16_t heading = -1;
 
// blink code for normal operation
if(CheckDelay(Led_Timer))
{
if(Calibration.Version != CALIBRATION_VERSION) LED_GRN_TOGGLE;
else LED_GRN_ON;
Led_Timer = SetDelay(150);
}
 
if(Calibration.Version != CALIBRATION_VERSION) heading = -1; // Version of the calibration Data does not match
else
{
switch(Orientation)
{
case ORIENTATION_NC:
Cx = (double)MagX;
Cy = (double)MagY;
Cz = (double)MagZ;
break;
 
case ORIENTATION_FC:
// rotation of 90 deg compared to NC setup
Cx = (double)MagY;
Cy = -(double)MagX;
Cz = (double)MagZ;
break;
}
 
// calculate nick and roll angle in rad
switch(AttitudeSource)
{
case ATTITUDE_SOURCE_I2C:
cli(); // stop interrupts
nick = I2C_WriteAttitude.Nick;
roll = I2C_WriteAttitude.Roll;
sei(); // start interrupts
break;
case ATTITUDE_SOURCE_UART:
cli(); // stop interrupts
nick = ExternData.Attitude[NICK];
roll = ExternData.Attitude[ROLL];
sei(); // start interrupts
break;
case ATTITUDE_SOURCE_ACC:
nick = AccAttitudeNick;
roll = AccAttitudeRoll;
break;
default:
nick = 0;
roll = 0;
break;
}
 
nick_rad = ((double)nick * M_PI) / 1800.0;
roll_rad = ((double)roll * M_PI) / 1800.0;
 
// calculate attitude correction
Hx = Cx * cos(nick_rad) - Cz * sin(nick_rad);
Hy = Cy * cos(roll_rad) + Cz * sin(roll_rad);
 
DebugOut.Analog[27] = (int16_t)Hx;
DebugOut.Analog[28] = (int16_t)Hy;
 
// calculate Heading
heading = (int16_t)((180.0 * atan2(Hy, Hx)) / M_PI);
// atan2 returns angular range from -180 deg to 180 deg in counter clockwise notation
// but the compass course is defined in a range from 0 deg to 360 deg clockwise notation.
if (heading < 0) heading = -heading;
else heading = 360 - heading;
}
// stop interrrupts during heading update to avoid transmitting heading between the update of both bytes of the int16_t
cli(); // stop interrupts
if(abs(heading) < 361) Heading = heading;
else (Heading = -1);
sei(); // start interrupts
}
 
void Calibrate(void)
{
uint8_t cal;
static uint8_t calold = 0;
static int16_t Xmin = 0, Xmax = 0, Ymin = 0, Ymax = 0, Zmin = 0, Zmax = 0;
static uint8_t blinkcount = 0;
static uint8_t invert_blinking = 0;
 
// check both sources of communication for calibration request
if(I2C_WriteCal.CalByte) cal = I2C_WriteCal.CalByte;
else cal = ExternData.CalState;
 
 
if(cal > 5) cal = 0;
// blink code for current calibration state
if(cal)
{
if(CheckDelay(Led_Timer) || (cal != calold))
{
if(blinkcount & 0x01) if(invert_blinking) LED_GRN_ON; else LED_GRN_OFF;
else if(invert_blinking) LED_GRN_OFF; else LED_GRN_ON;
 
// end of blinkcount sequence
if((blinkcount + 1 ) >= (2 * cal))
{
blinkcount = 0;
Led_Timer = SetDelay(1500);
}
else
{
blinkcount++;
Led_Timer = SetDelay(100);
}
}
}
else
{
if(invert_blinking) LED_GRN_ON; else LED_GRN_OFF;
}
// calibration state machine
switch(cal)
{
case 1: // 1st step of calibration
// initialize ranges
// used to change the orientation of the MK3MAG in the horizontal plane
Xmin = 10000;
Xmax = -10000;
Ymin = 10000;
Ymax = -10000;
Zmin = 10000;
Zmax = -10000;
Calibration.AccX.Offset = RawAccX;
Calibration.AccY.Offset = RawAccY;
Calibration.AccZ.Offset = RawAccZ;
invert_blinking = 0;
break;
 
case 2: // 2nd step of calibration
// find Min and Max of the X- and Y-Sensors during rotation in the horizontal plane
if(UncalMagX < Xmin) Xmin = UncalMagX;
if(UncalMagX > Xmax) Xmax = UncalMagX;
if(UncalMagY < Ymin) Ymin = UncalMagY;
if(UncalMagY > Ymax) Ymax = UncalMagY;
invert_blinking = 1;
break;
 
case 3: // 3rd step of calibration
// used to change the orientation of the MK3MAG vertical to the horizontal plane
invert_blinking = 0;
break;
 
case 4:
// find Min and Max of the Z-Sensor
if(UncalMagZ < Zmin) Zmin = UncalMagZ;
if(UncalMagZ > Zmax) Zmax = UncalMagZ;
invert_blinking = 1;
break;
 
case 5:
// Save values
if(cal != calold) // avoid continously writing of eeprom!
{
Calibration.MagX.Range = Xmax - Xmin;
Calibration.MagX.Offset = (Xmin + Xmax) / 2;
Calibration.MagY.Range = Ymax - Ymin;
Calibration.MagY.Offset = (Ymin + Ymax) / 2;
Calibration.MagZ.Range = Zmax - Zmin;
Calibration.MagZ.Offset = (Zmin + Zmax) / 2;
if((Calibration.MagX.Range > 150) && (Calibration.MagY.Range > 150) && (Calibration.MagZ.Range > 150))
{
Calibration.Version = CALIBRATION_VERSION;
// indicate write process by setting the led off for 2 seconds
LED_GRN_OFF;
eeprom_write_block(&Calibration, &eeCalibration, sizeof(Calibration));
Led_Timer = SetDelay(2000);
// reset blinkcode
blinkcount = 0;
}
else
{
// restore old calibration data from eeprom
eeprom_read_block(&Calibration, &eeCalibration, sizeof(Calibration));
}
}
invert_blinking = 0;
break;
 
default:
break;
}
calold = cal;
}
 
 
void SetDebugValues(void)
{
DebugOut.Analog[0] = MagX;
DebugOut.Analog[1] = MagY;
DebugOut.Analog[2] = MagZ;
DebugOut.Analog[3] = UncalMagX;
DebugOut.Analog[4] = UncalMagY;
DebugOut.Analog[5] = UncalMagZ;
switch(AttitudeSource)
{
case ATTITUDE_SOURCE_ACC:
DebugOut.Analog[6] = AccAttitudeNick;
DebugOut.Analog[7] = AccAttitudeRoll;
break;
 
case ATTITUDE_SOURCE_UART:
DebugOut.Analog[6] = ExternData.Attitude[NICK];
DebugOut.Analog[7] = ExternData.Attitude[ROLL];
break;
 
 
case ATTITUDE_SOURCE_I2C:
DebugOut.Analog[6] = I2C_WriteAttitude.Nick;
DebugOut.Analog[7] = I2C_WriteAttitude.Roll;
break;
}
DebugOut.Analog[8] = Calibration.MagX.Offset;
DebugOut.Analog[9] = Calibration.MagX.Range;
DebugOut.Analog[10] = Calibration.MagY.Offset;
DebugOut.Analog[11] = Calibration.MagY.Range;
DebugOut.Analog[12] = Calibration.MagZ.Offset;
DebugOut.Analog[13] = Calibration.MagZ.Range;
if(I2C_WriteCal.CalByte) DebugOut.Analog[14] = I2C_WriteCal.CalByte;
else DebugOut.Analog[14] = ExternData.CalState;
DebugOut.Analog[15] = Heading;
DebugOut.Analog[16] = ExternData.UserParam[0];
DebugOut.Analog[17] = ExternData.UserParam[1];
DebugOut.Analog[18] = AccX;
DebugOut.Analog[19] = AccY;
DebugOut.Analog[20] = AccZ;
DebugOut.Analog[21] = RawAccX;
DebugOut.Analog[22] = RawAccY;
DebugOut.Analog[23] = RawAccZ;
DebugOut.Analog[24] = Calibration.AccX.Offset;
DebugOut.Analog[25] = Calibration.AccY.Offset;
DebugOut.Analog[26] = Calibration.AccZ.Offset;
DebugOut.Analog[29] = AttitudeSource;
}
 
void AccMeasurement(void)
{
if(AccPresent)
{
RawAccX = (RawAccX + (int16_t)ADC_GetValue(ACC_X))/2;
RawAccY = (RawAccY + (int16_t)ADC_GetValue(ACC_Y))/2;
RawAccZ = (RawAccZ + (int16_t)ADC_GetValue(ACC_Z))/2;
}
else
{
RawAccX = 0;
RawAccY = 0;
RawAccZ = 0;
}
}
 
int main (void)
{
static uint8_t state = 0;
static uint16_t statetimer;
// reset input pullup
DDRC &=~((1<<DDC6));
PORTC |= (1<<PORTC6);
 
LED_Init();
TIMER0_Init();
USART0_Init();
ADC_Init();
I2C_Init();
 
sei(); // enable globale interrupts
USART0_Print("\n\rthe use of this software is only permitted\n\ron original MikroKopter-Hardware");
USART0_Print("\n\rwww.MikroKopter.de (c) HiSystems GmbH");
 
if(AccPresent)
{
USART0_Print("\n\nACC present\n");
}
 
LED_GRN_ON;
 
Led_Timer = SetDelay(200);
 
// read calibration info from eeprom
eeprom_read_block(&Calibration, &eeCalibration, sizeof(Calibration));
 
ExternData.CalState = 0;
I2C_WriteCal.CalByte = 0;
 
statetimer = SetDelay(0);
 
// main loop
while (1)
{
 
switch(state)
{
case 0:
if(CheckDelay(statetimer))
{
FLIP_LOW;
statetimer = SetDelay(2);
state = 1;
}
break;
 
case 1:
if(CheckDelay(statetimer))
{
RawMagnet1a = ADC_GetValue(MAG_X);
RawMagnet2a = -ADC_GetValue(MAG_Y);
RawMagnet3a = ADC_GetValue(MAG_Z);
AccMeasurement();
statetimer = SetDelay(1);
state = 2;
}
break;
 
case 2:
if(CheckDelay(statetimer))
{
FLIP_HIGH;
statetimer = SetDelay(2);
state = 3;
}
break;
 
case 3:
if(CheckDelay(statetimer))
{
RawMagnet1b = ADC_GetValue(MAG_X);
RawMagnet2b = -ADC_GetValue(MAG_Y);
RawMagnet3b = ADC_GetValue(MAG_Z);
AccMeasurement();
statetimer = SetDelay(1);
state = 0;
 
CalcFields();
if(ExternData.CalState || I2C_WriteCal.CalByte) Calibrate();
else CalcHeading();
if(NC_Connected) NC_Connected--;
if(FC_Connected) FC_Connected--;
if(PC_Connected) PC_Connected--;
// fall back to attitude estimation from onboard acc sensor if NC or FC does'nt send attitude data
if(!FC_Connected && ! NC_Connected)
{
AttitudeSource = ATTITUDE_SOURCE_ACC;
Orientation = ORIENTATION_FC;
}
}
break;
 
default: // should never happen
statetimer = SetDelay(0);
state = 0;
break;
} // one full state cylce is 6 ms
 
// check data from USART
USART0_ProcessRxData();
 
if(PC_Connected)
{
USART0_EnableTXD();
USART0_TransmitTxData();
}
else
{
USART0_DisableTXD();
}
} // while(1)
}
 
/tags/V0.22c/main.h
0,0 → 1,34
#ifndef _MAIN_H_
#define _MAIN_H_
 
 
#include <avr/eeprom.h>
#include <inttypes.h>
 
 
typedef enum
{
ATTITUDE_SOURCE_I2C = 0,
ATTITUDE_SOURCE_UART = 1,
ATTITUDE_SOURCE_ACC = 2
} AttitudeSource_t;
 
 
typedef enum
{
ORIENTATION_NC = 0,
ORIENTATION_FC = 1
} Orientation_t;
 
 
extern int16_t Heading;
 
extern AttitudeSource_t AttitudeSource;
extern Orientation_t Orientation;
 
extern int16_t MagX, MagY, MagZ;
 
void SetDebugValues(void);
 
#endif //_MAIN_H_
 
/tags/V0.22c/makefile
0,0 → 1,420
#--------------------------------------------------------------------
# MCU name
MCU = atmega168
F_CPU = 8000000
#-------------------------------------------------------------------
#BOARD = 10
BOARD = 11
VERSION_MAJOR = 0
VERSION_MINOR = 22
VERSION_PATCH = 2
 
VERSION_SERIAL_MAJOR = 10 # Serial Protocol Major Version
VERSION_SERIAL_MINOR = 0 # Serial Protocol Minor Version
NC_I2C_COMPATIBLE = 3 # I2C Protocol Version
#-------------------------------------------------------------------
 
# get SVN revision
REV := $(shell sh -c "cat .svn/entries | sed -n '4p'")
 
# Output format. (can be srec, ihex, binary)
FORMAT = ihex
 
# Target file name (without extension).
 
ifeq ($(VERSION_PATCH), 0)
TARGET = MK3Mag_MEGA168_V$(VERSION_MAJOR)_$(VERSION_MINOR)a_SVN$(REV)
endif
ifeq ($(VERSION_PATCH), 1)
TARGET = MK3Mag_MEGA168_V$(VERSION_MAJOR)_$(VERSION_MINOR)b_SVN$(REV)
endif
ifeq ($(VERSION_PATCH), 2)
TARGET = MK3Mag_MEGA168_V$(VERSION_MAJOR)_$(VERSION_MINOR)c_SVN$(REV)
endif
ifeq ($(VERSION_PATCH), 3)
TARGET = MK3Mag_MEGA168_V$(VERSION_MAJOR)_$(VERSION_MINOR)d_SVN$(REV)
endif
ifeq ($(VERSION_PATCH), 4)
TARGET = MK3Mag_MEGA168_V$(VERSION_MAJOR)_$(VERSION_MINOR)e_SVN$(REV)
endif
ifeq ($(VERSION_PATCH), 5)
TARGET = MK3Mag_MEGA168_V$(VERSION_MAJOR)_$(VERSION_MINOR)f_SVN$(REV)
endif
ifeq ($(VERSION_PATCH), 6)
TARGET = MK3Mag_MEGA168_V$(VERSION_MAJOR)_$(VERSION_MINOR)g_SVN$(REV)
endif
ifeq ($(VERSION_PATCH), 7)
TARGET = MK3Mag_MEGA168_V$(VERSION_MAJOR)_$(VERSION_MINOR)h_SVN$(REV)
endif
ifeq ($(VERSION_PATCH), 8)
TARGET = MK3Mag_MEGA168_V$(VERSION_MAJOR)_$(VERSION_MINOR)i_SVN$(REV)
endif
ifeq ($(VERSION_PATCH), 9)
TARGET = MK3Mag_MEGA168_V$(VERSION_MAJOR)_$(VERSION_MINOR)j_SVN$(REV)
endif
 
 
# Optimization level, can be [0, 1, 2, 3, s]. 0 turns off optimization.
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
OPT = 2
 
##########################################################################################################
# List C source files here. (C dependencies are automatically generated.)
SRC = main.c uart.c timer0.c analog.c twislave.c led.c menu.c printf_P.c
##########################################################################################################
 
 
# List Assembler source files here.
# Make them always end in a capital .S. Files ending in a lowercase .s
# will not be considered source files but generated files (assembler
# output from the compiler), and will be deleted upon "make clean"!
# Even though the DOS/Win* filesystem matches both .s and .S the same,
# it will preserve the spelling of the filenames, and gcc itself does
# care about how the name is spelled on its command-line.
ASRC =
 
 
# List any extra directories to look for include files here.
# Each directory must be seperated by a space.
EXTRAINCDIRS =
 
 
CDEFS = -DF_CPU=$(F_CPU)UL
 
# Optional compiler flags.
# -g: generate debugging information (for GDB, or for COFF conversion)
# -O*: optimization level
# -f...: tuning, see gcc manual and avr-libc documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -ahlms: create assembler listing
CFLAGS = -O$(OPT) \
-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \
-Wall -Wstrict-prototypes \
-Wa,-adhlns=$(<:.c=.lst) \
$(patsubst %,-I%,$(EXTRAINCDIRS))
 
 
# Set a "language standard" compiler flag.
# Unremark just one line below to set the language standard to use.
# gnu99 = C99 + GNU extensions. See GCC manual for more information.
#CFLAGS += -std=c89
#CFLAGS += -std=gnu89
#CFLAGS += -std=c99
CFLAGS += -std=gnu99
CFLAGS += $(CDEFS)
CFLAGS += -DVERSION_MAJOR=$(VERSION_MAJOR) -DVERSION_MINOR=$(VERSION_MINOR) -DVERSION_PATCH=$(VERSION_PATCH) -DVERSION_SERIAL_MAJOR=$(VERSION_SERIAL_MAJOR) -DVERSION_SERIAL_MINOR=$(VERSION_SERIAL_MINOR) -DBOARD=$(BOARD) -DNC_I2C_COMPATIBLE=$(NC_I2C_COMPATIBLE)
 
ifeq ($(AVR_CTRL_PLATINE), 1)
CFLAGS += -DAVR_CTRL_PLATINE=$(AVR_CTRL_PLATINE)
endif
 
 
 
# Optional assembler flags.
# -Wa,...: tell GCC to pass this to the assembler.
# -ahlms: create listing
# -gstabs: have the assembler create line number information; note that
# for use in COFF files, additional information about filenames
# and function names needs to be present in the assembler source
# files -- see avr-libc docs [FIXME: not yet described there]
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
 
 
 
# Optional linker flags.
# -Wl,...: tell GCC to pass this to linker.
# -Map: create map file
# --cref: add cross reference to map file
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
 
 
 
# Additional libraries
 
# Minimalistic printf version
#LDFLAGS += -Wl,-u,vfprintf -lprintf_min
 
# Floating point printf version (requires -lm below)
#LDFLAGS += -Wl,-u,vfprintf -lprintf_flt
 
# -lm = math library
LDFLAGS += -lm
 
 
 
 
# Programming support using avrdude. Settings and variables.
 
# Programming hardware: alf avr910 avrisp bascom bsd
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
#
# Type: avrdude -c ?
# to get a full listing.
#
 
AVRDUDE_PROGRAMMER = dt006
#AVRDUDE_PROGRAMMER = stk200
 
#AVRDUDE_PORT = com1 # programmer connected to serial device
AVRDUDE_PORT = lpt1 # programmer connected to parallel port
 
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
 
AVRDUDE_FLAGS = -F -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
 
# Uncomment the following if you want avrdude's erase cycle counter.
# Note that this counter needs to be initialized first using -Yn,
# see avrdude manual.
#AVRDUDE_ERASE += -y
 
# Uncomment the following if you do /not/ wish a verification to be
# performed after programming the device.
#AVRDUDE_FLAGS += -V -E noreset
 
 
# Increase verbosity level. Please use this when submitting bug
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
# to submit bug reports.
#AVRDUDE_FLAGS += -v -v
 
 
 
 
# ---------------------------------------------------------------------------
 
# Define directories, if needed.
DIRAVR = c:/winavr
DIRAVRBIN = $(DIRAVR)/bin
DIRAVRUTILS = $(DIRAVR)/utils/bin
DIRINC = .
DIRLIB = $(DIRAVR)/avr/lib
 
 
# Define programs and commands.
SHELL = sh
 
CC = avr-gcc
 
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
 
 
# Programming support using avrdude.
AVRDUDE = avrdude
 
 
REMOVE = rm -f
COPY = cp
 
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
ELFSIZE = $(SIZE) -A $(TARGET).elf
 
 
 
# Define Messages
# English
MSG_ERRORS_NONE = Errors: none
MSG_BEGIN = -------- begin --------
MSG_END = -------- end --------
MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after:
MSG_COFF = Converting to AVR COFF:
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
MSG_FLASH = Creating load file for Flash:
MSG_EEPROM = Creating load file for EEPROM:
MSG_EXTENDED_LISTING = Creating Extended Listing:
MSG_SYMBOL_TABLE = Creating Symbol Table:
MSG_LINKING = Linking:
MSG_COMPILING = Compiling:
MSG_ASSEMBLING = Assembling:
MSG_CLEANING = Cleaning project:
 
 
 
 
# Define all object files.
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
 
# Define all listing files.
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
 
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
 
 
 
# Default target.
all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \
$(TARGET).lss $(TARGET).sym sizeafter finished end
 
 
# Eye candy.
# AVR Studio 3.x does not check make's exit code but relies on
# the following magic strings to be generated by the compile job.
begin:
@echo
@echo $(MSG_BEGIN)
 
finished:
@echo $(MSG_ERRORS_NONE)
 
end:
@echo $(MSG_END)
@echo
 
 
# Display size of file.
sizebefore:
@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
 
sizeafter:
@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
 
 
 
# Display compiler version information.
gccversion :
@$(CC) --version
 
 
 
 
# Convert ELF to COFF for use in debugging / simulating in
# AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
--change-section-address .data-0x800000 \
--change-section-address .bss-0x800000 \
--change-section-address .noinit-0x800000 \
--change-section-address .eeprom-0x810000
 
 
coff: $(TARGET).elf
@echo
@echo $(MSG_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
 
 
extcoff: $(TARGET).elf
@echo
@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
 
 
 
 
# Program the device.
program: $(TARGET).hex $(TARGET).eep
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
 
 
 
 
# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
@echo
@echo $(MSG_FLASH) $@
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
 
%.eep: %.elf
@echo
@echo $(MSG_EEPROM) $@
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
 
# Create extended listing file from ELF output file.
%.lss: %.elf
@echo
@echo $(MSG_EXTENDED_LISTING) $@
$(OBJDUMP) -h -S $< > $@
 
# Create a symbol table from ELF output file.
%.sym: %.elf
@echo
@echo $(MSG_SYMBOL_TABLE) $@
avr-nm -n $< > $@
 
 
 
# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
@echo
@echo $(MSG_LINKING) $@
$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
 
 
# Compile: create object files from C source files.
%.o : %.c
@echo
@echo $(MSG_COMPILING) $<
$(CC) -c $(ALL_CFLAGS) $< -o $@
 
 
# Compile: create assembler files from C source files.
%.s : %.c
$(CC) -S $(ALL_CFLAGS) $< -o $@
 
 
# Assemble: create object files from assembler source files.
%.o : %.S
@echo
@echo $(MSG_ASSEMBLING) $<
$(CC) -c $(ALL_ASFLAGS) $< -o $@
 
 
 
 
 
 
# Target: clean project.
clean: begin clean_list finished end
 
clean_list :
@echo
@echo $(MSG_CLEANING)
# $(REMOVE) $(TARGET).hex
# $(REMOVE) $(TARGET).eep
# $(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).cof
$(REMOVE) $(TARGET).elf
$(REMOVE) $(TARGET).map
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).a90
$(REMOVE) $(TARGET).sym
$(REMOVE) $(TARGET).lnk
$(REMOVE) $(TARGET).lss
$(REMOVE) $(OBJ)
$(REMOVE) $(LST)
$(REMOVE) $(SRC:.c=.s)
$(REMOVE) $(SRC:.c=.d)
 
 
# Automatically generate C source code dependencies.
# (Code originally taken from the GNU make user manual and modified
# (See README.txt Credits).)
#
# Note that this will work with sh (bash) and sed that is shipped with WinAVR
# (see the SHELL variable defined above).
# This may not work with other shells or other seds.
#
%.d: %.c
set -e; $(CC) -MM $(ALL_CFLAGS) $< \
| sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \
[ -s $@ ] || rm -f $@
 
 
# Remove the '-' if you want to see the dependency files generated.
-include $(SRC:.c=.d)
 
 
 
# Listing of phony targets.
.PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff \
clean clean_list program
 
/tags/V0.22c/menu.c
0,0 → 1,102
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Copyright (c) 04.2007 Holger Buss
// + only for non-profit use
// + www.MikroKopter.com
// + see the File "License.txt" for further Informations
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
#include <stdlib.h>
#include <inttypes.h>
#include "menu.h"
#include "uart.h"
#include "printf_P.h"
#include "analog.h"
#include "main.h"
 
 
uint8_t MaxMenuItem = 2;
uint8_t MenuItem = 0;
uint8_t RemoteKeys = 0;
 
#define KEY1 0x01
#define KEY2 0x02
#define KEY3 0x04
#define KEY4 0x08
#define KEY5 0x10
 
 
int8_t DisplayBuff[DISPLAYBUFFSIZE] = "Hello World";
uint8_t DispPtr = 0;
 
 
/************************************/
/* Clear LCD Buffer */
/************************************/
void LCD_Clear(void)
{
uint8_t i;
for( i = 0; i < DISPLAYBUFFSIZE; i++) DisplayBuff[i] = ' ';
}
 
 
/************************************/
/* Update Menu on LCD */
/************************************/
// Display with 20 characters in 4 lines
void LCD_PrintMenu(void)
{
if(RemoteKeys & KEY1)
{
if(MenuItem) MenuItem--;
else MenuItem = MaxMenuItem;
}
if(RemoteKeys & KEY2)
{
if(MenuItem == MaxMenuItem) MenuItem = 0;
else MenuItem++;
}
if((RemoteKeys & KEY1) && (RemoteKeys & KEY2)) MenuItem = 0;
 
LCD_Clear();
 
if(MenuItem > MaxMenuItem) MenuItem = MaxMenuItem;
// print menu item number in the upper right corner
if(MenuItem < 10)
{
LCD_printfxy(17,0,"[%i]",MenuItem);
}
else
{
LCD_printfxy(16,0,"[%i]",MenuItem);
}
 
switch(MenuItem)
{
case 0:// Version Info Menu Item
LCD_printfxy(0,0,"++ MK3MAG ++ ");
LCD_printfxy(0,1," V %d.%d%c", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH + 'a');
if(AccPresent)
{
LCD_printfxy(0,2, " ACC Support ");
}
else
{
LCD_printfxy(0,2, " ");
}
LCD_printfxy(0,3,"(c) Buss, Busker ");
break;
 
case 1: // Magnet readings
LCD_printfxy(0,0,"Magnet Sensors: ");
LCD_printfxy(0,1,"X:%+4d ", MagX);
LCD_printfxy(0,2,"Y:%+4d ", MagY);
LCD_printfxy(0,3,"Z:%+4d ", MagZ);
break;
 
default:
MaxMenuItem = MenuItem - 1;
MenuItem = 0;
break;
}
RemoteKeys = 0;
}
/tags/V0.22c/menu.h
0,0 → 1,18
#ifndef _MENU_H
#define _MENU_H
 
#include <inttypes.h>
 
#define DISPLAYBUFFSIZE 80
 
extern void LCD_PrintMenu(void);
extern void LCD_Clear(void);
extern int8_t DisplayBuff[];
extern uint8_t DispPtr;
extern uint8_t MenuItem;
extern uint8_t MaxMenuItem;
extern uint8_t RemoteKeys;
 
#endif //_MENU_H
 
 
/tags/V0.22c/old_macros.h
0,0 → 1,47
/*
For backwards compatibility only.
Ingo Busker ingo@mikrocontroller.com
*/
 
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
 
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
 
#ifndef inb
#define inb(sfr) _SFR_BYTE(sfr)
#endif
 
#ifndef outb
#define outb(sfr, val) (_SFR_BYTE(sfr) = (val))
#endif
 
#ifndef inw
#define inw(sfr) _SFR_WORD(sfr)
#endif
 
#ifndef outw
#define outw(sfr, val) (_SFR_WORD(sfr) = (val))
#endif
 
#ifndef outp
#define outp(val, sfr) outb(sfr, val)
#endif
 
#ifndef inp
#define inp(sfr) inb(sfr)
#endif
 
#ifndef BV
#define BV(bit) _BV(bit)
#endif
 
 
#ifndef PRG_RDB
#define PRG_RDB pgm_read_byte
#endif
 
/tags/V0.22c/printf_P.c
0,0 → 1,483
// Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist nicht von der Lizenz für den MikroKopter-Teil unterstellt
 
/*
Copyright (C) 1993 Free Software Foundation
 
This file is part of the GNU IO Library. This library 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, or (at your option)
any later version.
 
This library 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 library; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
 
/*
* Copyright (c) 1990 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. [rescinded 22 July 1999]
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
 
/******************************************************************************
This file is a patched version of printf called _printf_P
It is made to work with avr-gcc for Atmel AVR MCUs.
There are some differences from standard printf:
1. There is no floating point support (with fp the code is about 8K!)
2. Return type is void
3. Format string must be in program memory (by using macro printf this is
done automaticaly)
4. %n is not implemented (just remove the comment around it if you need it)
5. If LIGHTPRINTF is defined, the code is about 550 bytes smaller and the
folowing specifiers are disabled :
space # * . - + p s o O
6. A function void uart_sendchar(char c) is used for output. The UART must
be initialized before using printf.
 
Alexander Popov
sasho@vip.orbitel.bg
******************************************************************************/
 
/*
* Actual printf innards.
*
* This code is large and complicated...
*/
 
#include <string.h>
#ifdef __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
 
#include "old_macros.h"
#include "printf_P.h"
#include "menu.h"
#include "uart.h"
 
 
//#define LIGHTPRINTF
char PrintZiel;
 
 
char Putchar(char zeichen)
{
if(PrintZiel == OUT_LCD) { DisplayBuff[DispPtr++] = zeichen; return(1);}
else return(USART0_putchar(zeichen));
}
 
 
void PRINT(const char * ptr, unsigned int len)
{
for(;len;len--) Putchar(*ptr++);
}
 
void PRINTP(const char * ptr, unsigned int len)
{
for(;len;len--) Putchar(pgm_read_byte(ptr++));
}
 
void PAD_SP(signed char howmany)
{
for(;howmany>0;howmany--) Putchar(' ');
}
 
void PAD_0(signed char howmany)
{
for(;howmany>0;howmany--) Putchar('0');
}
 
#define BUF 40
 
/*
* Macros for converting digits to letters and vice versa
*/
#define to_digit(c) ((c) - '0')
#define is_digit(c) ((c)<='9' && (c)>='0')
#define to_char(n) ((n) + '0')
 
/*
* Flags used during conversion.
*/
#define LONGINT 0x01 /* long integer */
#define LONGDBL 0x02 /* long double; unimplemented */
#define SHORTINT 0x04 /* short integer */
#define ALT 0x08 /* alternate form */
#define LADJUST 0x10 /* left adjustment */
#define ZEROPAD 0x20 /* zero (as opposed to blank) pad */
#define HEXPREFIX 0x40 /* add 0x or 0X prefix */
 
void _printf_P (char ziel,char const *fmt0, ...) /* Works with string from FLASH */
{
va_list ap;
register const char *fmt; /* format string */
register char ch; /* character from fmt */
register int n; /* handy integer (short term usage) */
register char *cp; /* handy char pointer (short term usage) */
const char *fmark; /* for remembering a place in fmt */
register unsigned char flags; /* flags as above */
signed char width; /* width from format (%8d), or 0 */
signed char prec; /* precision from format (%.3d), or -1 */
char sign; /* sign prefix (' ', '+', '-', or \0) */
unsigned long _ulong=0; /* integer arguments %[diouxX] */
#define OCT 8
#define DEC 10
#define HEX 16
unsigned char base; /* base for [diouxX] conversion */
signed char dprec; /* a copy of prec if [diouxX], 0 otherwise */
signed char dpad; /* extra 0 padding needed for integers */
signed char fieldsz; /* field size expanded by sign, dpad etc */
/* The initialization of 'size' is to suppress a warning that
'size' might be used unitialized. It seems gcc can't
quite grok this spaghetti code ... */
signed char size = 0; /* size of converted field or string */
char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */
char ox[2]; /* space for 0x hex-prefix */
 
PrintZiel = ziel; // bestimmt, LCD oder UART
va_start(ap, fmt0);
 
fmt = fmt0;
 
/*
* Scan the format for conversions (`%' character).
*/
for (;;) {
for (fmark = fmt; (ch = pgm_read_byte(fmt)) != '\0' && ch != '%'; fmt++)
/* void */;
if ((n = fmt - fmark) != 0) {
PRINTP(fmark, n);
}
if (ch == '\0')
goto done;
fmt++; /* skip over '%' */
 
flags = 0;
dprec = 0;
width = 0;
prec = -1;
sign = '\0';
 
rflag: ch = PRG_RDB(fmt++);
reswitch:
#ifdef LIGHTPRINTF
if (ch=='o' || ch=='u' || (ch|0x20)=='x') {
#else
if (ch=='u' || (ch|0x20)=='x') {
#endif
if (flags&LONGINT) {
_ulong=va_arg(ap, unsigned long);
} else {
register unsigned int _d;
_d=va_arg(ap, unsigned int);
_ulong = flags&SHORTINT ? (unsigned long)(unsigned short)_d : (unsigned long)_d;
}
}
 
#ifndef LIGHTPRINTF
if(ch==' ') {
/*
* ``If the space and + flags both appear, the space
* flag will be ignored.''
* -- ANSI X3J11
*/
if (!sign)
sign = ' ';
goto rflag;
} else if (ch=='#') {
flags |= ALT;
goto rflag;
} else if (ch=='*'||ch=='-') {
if (ch=='*') {
/*
* ``A negative field width argument is taken as a
* - flag followed by a positive field width.''
* -- ANSI X3J11
* They don't exclude field widths read from args.
*/
if ((width = va_arg(ap, int)) >= 0)
goto rflag;
width = -width;
}
flags |= LADJUST;
flags &= ~ZEROPAD; /* '-' disables '0' */
goto rflag;
} else if (ch=='+') {
sign = '+';
goto rflag;
} else if (ch=='.') {
if ((ch = PRG_RDB(fmt++)) == '*') {
n = va_arg(ap, int);
prec = n < 0 ? -1 : n;
goto rflag;
}
n = 0;
while (is_digit(ch)) {
n = n*10 + to_digit(ch);
ch = PRG_RDB(fmt++);
}
prec = n < 0 ? -1 : n;
goto reswitch;
} else
#endif /* LIGHTPRINTF */
if (ch=='0') {
/*
* ``Note that 0 is taken as a flag, not as the
* beginning of a field width.''
* -- ANSI X3J11
*/
if (!(flags & LADJUST))
flags |= ZEROPAD; /* '-' disables '0' */
goto rflag;
} else if (ch>='1' && ch<='9') {
n = 0;
do {
n = 10 * n + to_digit(ch);
ch = PRG_RDB(fmt++);
} while (is_digit(ch));
width = n;
goto reswitch;
} else if (ch=='h') {
flags |= SHORTINT;
goto rflag;
} else if (ch=='l') {
flags |= LONGINT;
goto rflag;
} else if (ch=='c') {
*(cp = buf) = va_arg(ap, int);
size = 1;
sign = '\0';
} else if (ch=='D'||ch=='d'||ch=='i') {
if(ch=='D')
flags |= LONGINT;
if (flags&LONGINT) {
_ulong=va_arg(ap, long);
} else {
register int _d;
_d=va_arg(ap, int);
_ulong = flags&SHORTINT ? (long)(short)_d : (long)_d;
}
 
if ((long)_ulong < 0) {
_ulong = -_ulong;
sign = '-';
}
base = DEC;
goto number;
} else
/*
if (ch=='n') {
if (flags & LONGINT)
*va_arg(ap, long *) = ret;
else if (flags & SHORTINT)
*va_arg(ap, short *) = ret;
else
*va_arg(ap, int *) = ret;
continue; // no output
} else
*/
#ifndef LIGHTPRINTF
if (ch=='O'||ch=='o') {
if (ch=='O')
flags |= LONGINT;
base = OCT;
goto nosign;
} else if (ch=='p') {
/*
* ``The argument shall be a pointer to void. The
* value of the pointer is converted to a sequence
* of printable characters, in an implementation-
* defined manner.''
* -- ANSI X3J11
*/
/* NOSTRICT */
_ulong = (unsigned int)va_arg(ap, void *);
base = HEX;
flags |= HEXPREFIX;
ch = 'x';
goto nosign;
} else if (ch=='s') { // print a string from RAM
if ((cp = va_arg(ap, char *)) == NULL) {
cp=buf;
cp[0] = '(';
cp[1] = 'n';
cp[2] = 'u';
cp[4] = cp[3] = 'l';
cp[5] = ')';
cp[6] = '\0';
}
if (prec >= 0) {
/*
* can't use strlen; can only look for the
* NUL in the first `prec' characters, and
* strlen() will go further.
*/
char *p = (char*)memchr(cp, 0, prec);
 
if (p != NULL) {
size = p - cp;
if (size > prec)
size = prec;
} else
size = prec;
} else
size = strlen(cp);
sign = '\0';
} else
#endif /* LIGHTPRINTF */
if(ch=='U'||ch=='u') {
if (ch=='U')
flags |= LONGINT;
base = DEC;
goto nosign;
} else if (ch=='X'||ch=='x') {
base = HEX;
/* leading 0x/X only if non-zero */
if (flags & ALT && _ulong != 0)
flags |= HEXPREFIX;
 
/* unsigned conversions */
nosign: sign = '\0';
/*
* ``... diouXx conversions ... if a precision is
* specified, the 0 flag will be ignored.''
* -- ANSI X3J11
*/
number: if ((dprec = prec) >= 0)
flags &= ~ZEROPAD;
 
/*
* ``The result of converting a zero value with an
* explicit precision of zero is no characters.''
* -- ANSI X3J11
*/
cp = buf + BUF;
if (_ulong != 0 || prec != 0) {
register unsigned char _d,notlastdigit;
do {
notlastdigit=(_ulong>=base);
_d = _ulong % base;
 
if (_d<10) {
_d+='0';
} else {
_d+='a'-10;
if (ch=='X') _d&=~0x20;
}
*--cp=_d;
_ulong /= base;
} while (notlastdigit);
#ifndef LIGHTPRINTF
// handle octal leading 0
if (base==OCT && flags & ALT && *cp != '0')
*--cp = '0';
#endif
}
 
size = buf + BUF - cp;
} else { //default
/* "%?" prints ?, unless ? is NUL */
if (ch == '\0')
goto done;
/* pretend it was %c with argument ch */
cp = buf;
*cp = ch;
size = 1;
sign = '\0';
}
 
/*
* All reasonable formats wind up here. At this point,
* `cp' points to a string which (if not flags&LADJUST)
* should be padded out to `width' places. If
* flags&ZEROPAD, it should first be prefixed by any
* sign or other prefix; otherwise, it should be blank
* padded before the prefix is emitted. After any
* left-hand padding and prefixing, emit zeroes
* required by a decimal [diouxX] precision, then print
* the string proper, then emit zeroes required by any
* leftover floating precision; finally, if LADJUST,
* pad with blanks.
*/
 
/*
* compute actual size, so we know how much to pad.
*/
fieldsz = size;
 
dpad = dprec - size;
if (dpad < 0)
dpad = 0;
 
if (sign)
fieldsz++;
else if (flags & HEXPREFIX)
fieldsz += 2;
fieldsz += dpad;
 
/* right-adjusting blank padding */
if ((flags & (LADJUST|ZEROPAD)) == 0)
PAD_SP(width - fieldsz);
 
/* prefix */
if (sign) {
PRINT(&sign, 1);
} else if (flags & HEXPREFIX) {
ox[0] = '0';
ox[1] = ch;
PRINT(ox, 2);
}
 
/* right-adjusting zero padding */
if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD)
PAD_0(width - fieldsz);
 
/* leading zeroes from decimal precision */
PAD_0(dpad);
 
/* the string or number proper */
PRINT(cp, size);
 
/* left-adjusting padding (always blank) */
if (flags & LADJUST)
PAD_SP(width - fieldsz);
}
done:
va_end(ap);
}
/tags/V0.22c/printf_P.h
0,0 → 1,19
#ifndef _PRINTF_P_H_
#define _PRINTF_P_H_
 
#include <avr/pgmspace.h>
 
#define OUT_V24 0
#define OUT_LCD 1
 
 
void _printf_P (char, char const *fmt0, ...);
extern char PrintZiel;
 
 
#define printf_P(format, args...) _printf_P(OUT_V24,format , ## args)
#define printf(format, args...) _printf_P(OUT_V24,PSTR(format) , ## args)
#define LCD_printfxy(x,y,format, args...) { DispPtr = y * 20 + x; _printf_P(OUT_LCD,PSTR(format) , ## args);}
#define LCD_printf(format, args...) { _printf_P(OUT_LCD,PSTR(format) , ## args);}
 
#endif
/tags/V0.22c/timer0.c
0,0 → 1,170
/*#######################################################################################
MK3Mag 3D-Magnet sensor
!!! THIS IS NOT FREE SOFTWARE !!!
#######################################################################################*/
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Copyright (c) 05.2008 Holger Buss
// + Thanks to Ilja Fähnrich (P_Latzhalter)
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
// + www.MikroKopter.com
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
// + mit unserer Zustimmung zulässig
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
// + AUSNAHME: Ein bei www.mikrokopter.de erworbener vorbestückter MK3Mag darf als Baugruppe auch in kommerziellen Systemen verbaut werden
// + Im Zweifelsfall bitte anfragen bei: info@mikrokopter.de
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
// + eindeutig als Ursprung verlinkt werden
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
// + Benutzung auf eigene Gefahr
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
// + mit unserer Zustimmung zulässig
/// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
// + this list of conditions and the following disclaimer.
// + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
// + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
// + from this software without specific prior written permission.
// + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
// + for non-commercial use (directly or indirectly)
// + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
// + with our written permission
// + Exception: A preassembled MK3Mag, purchased from www.mikrokopter.de may be used as a part of commercial systems
// + In case of doubt please contact: info@MikroKopter.de
// + * If sources or documentations are redistributet on other webpages, our webpage (http://www.MikroKopter.de) must be
// + clearly linked as origin
// + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// + POSSIBILITY OF SUCH DAMAGE.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "main.h"
 
volatile uint16_t CountMilliseconds = 0;
volatile uint16_t I2C_Timeout = 0;
 
 
/*****************************************************/
/* Initialize Timer 0 */
/*****************************************************/
void TIMER0_Init(void)
{
// set PB2 as output for the PWM used to signal compass heading
DDRB |= (1<<DDB2);
PORTB &= ~(1<<PORTB2);
 
 
// Timer/Counter 0 Control Register A
 
// Normal Timer Counter Mode (Bits WGM02 = 0, WGM01 = 0, WGM00 = 0)
// OC0A disconnected (Bits COM0A1 = 0, COM0A0 = 0)
// OC0B disconnected (Bits COM0B1 = 0, COM0B0 = 0)
TCCR0A &= ~((1<<COM0A1)|(1<<COM0A0)|(1<<COM0B1)|(1<<COM0B0)|(1<<WGM01)|(1<<WGM00));
 
// Timer/Counter 0 Control Register B
 
// set clock devider for timer 0 to SYSKLOCK/8 = 8MHz / 8 = 1MHz
// i.e. the timer increments from 0x00 to 0xFF with an update rate of 2.5 MHz
// hence the timer overflow interrupt frequency is 2.5 MHz / 256 = 9.765 kHz
 
// divider 8 (Bits CS02 = 0, CS01 = 1, CS00 = 0)
TCCR0B &= ~((1<<FOC0A)|(1<<FOC0B)|(1<<WGM02)|(1<<CS02));
TCCR0B = (1<<CS01)|(0<<CS00);
 
// init Timer/Counter 0 Register
TCNT0 = 0;
 
// Timer/Counter 0 Interrupt Mask Register
// enable timer overflow interrupt only
TIMSK0 &= ~((1<<OCIE0B)|(1<<OCIE0A));
TIMSK0 |= (1<<TOIE0);
 
}
 
 
// -----------------------------------------------------------------------
ISR(TIMER0_OVF_vect)
{
static uint8_t cnt;
static uint16_t cmps_cnt;
 
// reload timer register so that overflow occurs after 100 increments at 1 MHz
// resulting in a calling rate of this ISR of 10kHz or 0.1 ms.
TCNT0 -= 101;
 
// disable PWM when bad compass heading value
if(Heading < 0)
{
PORTB &= ~(1<<PORTB2);
cmps_cnt = 0;
}
else
{
// if a periode of 38.0 ms is over
if(++cmps_cnt >= 380)
{
// set PWM out to high
PORTB |= (1<<PORTB2);
// reset periode counter
cmps_cnt = 0;
}
// if the delay in 0.1 ms is equal to Heading + 10
else if(cmps_cnt >= (Heading + 10))
{
// set PWM out to low
PORTB &= ~(1<<PORTB2);
}
}
 
if(!--cnt)
{
// every 10th run (1kHz or 1ms)
cnt = 10;
CountMilliseconds++;
if(I2C_Timeout) I2C_Timeout--;
}
}
 
 
// -----------------------------------------------------------------------
uint16_t SetDelay (uint16_t t)
{
return(CountMilliseconds + t - 1);
}
 
// -----------------------------------------------------------------------
int8_t CheckDelay(uint16_t t)
{
return(((t - CountMilliseconds) & 0x8000) >> 8); // check sign bit
}
 
// -----------------------------------------------------------------------
void Delay_ms(uint16_t wait)
{
uint16_t t_stop;
t_stop = SetDelay(wait);
while (!CheckDelay(t_stop));
}
 
/tags/V0.22c/timer0.h
0,0 → 1,17
#ifndef _TIMER0_H
#define _TIMER0_H
 
#include <inttypes.h>
 
extern volatile uint16_t CountMilliseconds;
extern volatile uint16_t I2C_Timeout;
 
 
void TIMER0_Init(void);
uint16_t SetDelay (uint16_t t);
int8_t CheckDelay(uint16_t t);
void Delay_ms(uint16_t wait);
 
 
#endif //_TIMER0_H
 
/tags/V0.22c/twislave.c
0,0 → 1,293
/*#######################################################################################
MK3Mag 3D-Magnet sensor
!!! THIS IS NOT FREE SOFTWARE !!!
#######################################################################################*/
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Copyright (c) 05.2008 Holger Buss
// + Thanks to Ilja Fähnrich (P_Latzhalter)
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
// + www.MikroKopter.com
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
// + mit unserer Zustimmung zulässig
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
// + AUSNAHME: Ein bei www.mikrokopter.de erworbener vorbestückter MK3Mag darf als Baugruppe auch in kommerziellen Systemen verbaut werden
// + Im Zweifelsfall bitte anfragen bei: info@mikrokopter.de
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
// + eindeutig als Ursprung verlinkt werden
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
// + Benutzung auf eigene Gefahr
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
// + mit unserer Zustimmung zulässig
/// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
// + this list of conditions and the following disclaimer.
// + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
// + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
// + from this software without specific prior written permission.
// + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
// + for non-commercial use (directly or indirectly)
// + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
// + with our written permission
// + Exception: A preassembled MK3Mag, purchased from www.mikrokopter.de may be used as a part of commercial systems
// + In case of doubt please contact: info@MikroKopter.de
// + * If sources or documentations are redistributet on other webpages, our webpage (http://www.MikroKopter.de) must be
// + clearly linked as origin
// + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// + POSSIBILITY OF SUCH DAMAGE.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/twi.h>
#include "twislave.h"
#include "uart.h"
#include "main.h"
#include "timer0.h"
#include "led.h"
 
 
volatile uint8_t I2C_RxBufferSize = 0, I2C_TxBufferSize = 0;
volatile uint8_t *I2C_TxBuffer = 0, *I2C_RxBuffer = 0;
volatile uint8_t Tx_Idx = 0, Rx_Idx = 0;
 
volatile uint8_t I2C_PrimRxBuffer[10];
 
uint8_t NC_Connected = 0;
I2C_Heading_t I2C_Heading;
I2C_WriteAttitude_t I2C_WriteAttitude;
I2C_Mag_t I2C_Mag;
I2C_Version_t I2C_Version;
I2C_WriteCal_t I2C_WriteCal;
 
// send ACK after recieving a byte / ACK is expected after transmitting a byte
#define TWCR_ACK TWCR = (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(1<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|(0<<TWWC)
// send no ACK after recieving a byte / No ACK is expected after transmitting a byte
#define TWCR_NACK TWCR = (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(0<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|(0<<TWWC)
// switched to the non adressed slave mode
#define TWCR_RESET TWCR = (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(1<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|(0<<TWWC)
// The bit pattern for TWCR_ACK and TWCR_RESET are equal. This is no errro but used for better understanding.
#define TWCR_CLEARBUS TWCR = (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(1<<TWEA)|(0<<TWSTA)|(1<<TWSTO)|(0<<TWWC)
 
void I2C_Init(void)
{
 
uint8_t sreg;
 
// backup status register
sreg = SREG;
// disable global interrupts
cli();
 
// SCK/SCL and MISO/SDA are at put together on the same connector pin in the schematic
 
// set PB4 (SCK) and PB5 (MISO) as input pull up
DDRB &= ~((1<<DDB4)|(1<<DDB5));
PORTB |= ((1<<PORTB4)|(1<<PORTB5));
 
// set PC4 (SDA) and PC5 (SCL) as input tristate
DDRC &= ~((1<<DDC4)|(1<<DDC5));
PORTC &= ~((1<<PORTC4)|(1<<PORTC5));
 
I2C_TxBuffer = 0;
Tx_Idx = 0;
I2C_TxBufferSize = 0;
I2C_RxBuffer = 0;
Rx_Idx = 0;
I2C_RxBufferSize = 0;
 
TWCR = ~(1<<TWSTA)|(1<<TWSTO);
TWCR|= (1<<TWEA) | (1<<TWEN)|(1<<TWIE);
 
// set own address
// set own address in the upper 7 bits
TWAR = I2C_SLAVE_ADDRESS; // set own address only the upper 7 bits are relevant
// TWI Control Register
// enable TWI Acknowledge Bit (TWEA = 1)
// disable TWI START Condition Bit (TWSTA = 0), SLAVE
// disable TWI STOP Condition Bit (TWSTO = 0), SLAVE
// enable TWI (TWEN = 1)
// enable TWI Interrupt (TWIE = 1)
TWCR |= (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(1<<TWEA)|(0<<TWSTA)|(1<<TWSTO)|(0<<TWWC);
// update version info
I2C_Version.Major = VERSION_MAJOR;
I2C_Version.Minor = VERSION_MINOR;
I2C_Version.Patch = VERSION_PATCH;
I2C_Version.Compatible = NC_I2C_COMPATIBLE;
TWCR_RESET;
// resore status register
SREG = sreg;
}
 
 
ISR (TWI_vect)
{
uint8_t data;
static uint8_t crc;
// check event
switch (TW_STATUS)
{
case TW_SR_SLA_ACK: // slave addressed in receiver mode and ack has been returned
Rx_Idx = 0xFF; // reset rx buffer pointer
TWCR_ACK; // trigger receiving of first data byte and send ack afterwards
return;
 
case TW_SR_DATA_ACK: // data has been received and ack has been returned
data = TWDR;
if (Rx_Idx == 0xFF)
{ // if the first byte after slave addressing was received
switch(data)
{
case I2C_CMD_VERSION:
I2C_TxBuffer = (uint8_t *)&I2C_Version;
I2C_TxBufferSize = sizeof(I2C_Version);
I2C_RxBuffer = 0;
I2C_RxBufferSize = 0;
break;
 
case I2C_CMD_WRITE_CAL:
I2C_TxBuffer = (uint8_t *)&I2C_WriteCal;
I2C_TxBufferSize = sizeof(I2C_WriteCal);
I2C_RxBuffer = (uint8_t *)&I2C_WriteCal;
I2C_RxBufferSize = sizeof(I2C_WriteCal);
break;
 
case I2C_CMD_READ_MAG:
I2C_TxBuffer = (uint8_t *)&I2C_Mag;
I2C_TxBufferSize = sizeof(I2C_Mag);
I2C_RxBuffer = 0;
I2C_RxBufferSize = 0;
 
I2C_Mag.MagX = MagX;
I2C_Mag.MagY = MagY;
I2C_Mag.MagZ = MagZ;
break;
 
case I2C_CMD_READ_HEADING:
I2C_TxBuffer = (uint8_t *)&I2C_Heading;
I2C_TxBufferSize = sizeof(I2C_Heading);
I2C_RxBuffer = (uint8_t *)&I2C_WriteAttitude;
I2C_RxBufferSize = sizeof(I2C_WriteAttitude);
I2C_Heading.Heading = Heading; // get heading
AttitudeSource = ATTITUDE_SOURCE_I2C;
Orientation = ORIENTATION_NC;
NC_Connected = 255;
break;
default: // unknown command id
I2C_RxBuffer = 0;
I2C_RxBufferSize = 0;
I2C_TxBuffer = 0;
I2C_TxBufferSize = 0;
break;
}
Rx_Idx = 0; // set rx buffer index to start of the buffer
crc = data;
}
else // Rx_Idx != 0xFF
{
// fill receiver buffer with the byte that has been received
// if buffer exist and there is still some free space
if(Rx_Idx < I2C_RxBufferSize)
{
I2C_PrimRxBuffer[Rx_Idx] = data;
crc += data;
}
else if (Rx_Idx == I2C_RxBufferSize) // crc byte was transfered
{ // if checksum matched
crc = ~crc; //flip all bits inthe checksum
if(crc == data)
{ // and RxBuffer exist
if(I2C_RxBuffer != 0)
{ // copy data to rx buffer
for(data = 0; data < I2C_RxBufferSize; data++)
{
I2C_RxBuffer[data] = I2C_PrimRxBuffer[data];
}
}
DebugOut.Analog[31]++;
}
else
{
DebugOut.Analog[30]++;
}
}
// else ignore data
Rx_Idx++;
}
TWCR_ACK;
return;
 
case TW_ST_SLA_ACK: // slave transmitter selected
// reset index to start of tx buffer
Tx_Idx = 0;
crc = 0;
// if tx buffer exist and there is at least one byte to transfer
if((I2C_TxBuffer != 0) && (I2C_TxBufferSize > 1))
{
data = I2C_TxBuffer[Tx_Idx];
 
}
else
{ // send 0x00 if no tx buffer exist or all bytes of the tx buffer have been transmitted
data = 0x00;
}
crc += data;
Tx_Idx++;
TWDR = data;
TWCR_ACK;
return;
 
case TW_ST_DATA_ACK: // data byte has been transmitted ack has been received
// put next byte from tx buffer to the data register
if((I2C_TxBuffer != 0) && (Tx_Idx < I2C_TxBufferSize))
{
data = I2C_TxBuffer[Tx_Idx];
crc += data;
}
else if (Tx_Idx == I2C_TxBufferSize)
{ // send crc byte at the end
data = ~crc;
}
else
{
data = 0x00;
}
Tx_Idx++;
TWDR = data;
TWCR_ACK;
return;
 
case TW_BUS_ERROR: // Bus-Error
TWCR_CLEARBUS; // free bus, reset to nonselected slave
return;
 
case TW_ST_DATA_NACK: // data transmitted, NACK received
case TW_ST_LAST_DATA: // last data byte transmitted, ACK received
case TW_SR_STOP: // stop or repeated start condition received while selected
default:
TWCR_RESET; // switch to the not addressed slave mode, own SLA will be recognized
return;
}
}
 
 
/tags/V0.22c/twislave.h
0,0 → 1,63
#ifndef _TWI_SLAVE_H_
#define _TWI_SLAVE_H_
 
#include <inttypes.h>
 
#define I2C_SLAVE_ADDRESS 0x50
 
#define I2C_CMD_VERSION 0x01
#define I2C_CMD_READ_MAG 0x02
#define I2C_CMD_READ_HEADING 0x03
#define I2C_CMD_WRITE_CAL 0x04
#define I2C_CMD_WRITE_EEPROM 0x0A
#define I2C_CMD_READ_EEPROM 0x0B
 
 
typedef struct
{
uint8_t Major;
uint8_t Minor;
uint8_t Patch;
uint8_t Compatible;
} I2C_Version_t;
 
typedef struct
{
int16_t MagX;
int16_t MagY;
int16_t MagZ;
} I2C_Mag_t;
 
 
typedef struct
{
int16_t Nick;
int16_t Roll;
} I2C_WriteAttitude_t;
 
 
typedef struct
{
uint8_t CalByte;
uint8_t Dummy1;
uint8_t Dummy2;
} I2C_WriteCal_t;
 
typedef struct
{
int16_t Heading;
} I2C_Heading_t;
 
extern uint8_t NC_Connected;
extern I2C_Heading_t I2C_Heading;
extern I2C_WriteAttitude_t I2C_WriteAttitude;
extern I2C_Mag_t I2C_Mag;
extern I2C_Version_t I2C_Version;
extern I2C_WriteCal_t I2C_WriteCal;
 
 
void I2C_Init(void);
 
 
#endif // _TWI_SLAVE_H_
 
/tags/V0.22c/uart.c
0,0 → 1,655
/*#######################################################################################
MK3Mag 3D-Magnet sensor
!!! THIS IS NOT FREE SOFTWARE !!!
#######################################################################################*/
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Copyright (c) 05.2008 Holger Buss
// + Thanks to Ilja Fähnrich (P_Latzhalter)
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
// + www.MikroKopter.com
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
// + mit unserer Zustimmung zulässig
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
// + AUSNAHME: Ein bei www.mikrokopter.de erworbener vorbestückter MK3Mag darf als Baugruppe auch in kommerziellen Systemen verbaut werden
// + Im Zweifelsfall bitte anfragen bei: info@mikrokopter.de
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
// + eindeutig als Ursprung verlinkt werden
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
// + Benutzung auf eigene Gefahr
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
// + mit unserer Zustimmung zulässig
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
// + this list of conditions and the following disclaimer.
// + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
// + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
// + from this software without specific prior written permission.
// + * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
// + for non-commercial use (directly or indirectly)
// + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
// + with our written permission
// + Exception: A preassembled MK3Mag, purchased from www.mikrokopter.de may be used as a part of commercial systems
// + In case of doubt please contact: info@MikroKopter.de
// + * If sources or documentations are redistributet on other webpages, our webpage (http://www.MikroKopter.de) must be
// + clearly linked as origin
// + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// + POSSIBILITY OF SUCH DAMAGE.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include <avr/pgmspace.h>
#include <stdarg.h>
#include <string.h>
#include "main.h"
#include "menu.h"
#include "uart.h"
#include "timer0.h"
#include "twislave.h"
 
// slave addresses
#define FC_ADDRESS 1
#define NC_ADDRESS 2
#define MK3MAG_ADDRESS 3
 
#define FALSE 0
#define TRUE 1
 
// keep buffers as small as possible
#define TXD_BUFFER_LEN 100
#define RXD_BUFFER_LEN 30
 
volatile uint8_t txd_buffer[TXD_BUFFER_LEN];
volatile uint8_t rxd_buffer_locked = FALSE;
volatile uint8_t rxd_buffer[RXD_BUFFER_LEN];
volatile uint8_t txd_complete = TRUE;
volatile uint8_t ReceivedBytes = 0;
volatile uint8_t *pRxData = 0;
volatile uint8_t RxDataLen = 0;
 
// send flags
#define RQST_VERSION_INFO 0x01
#define RQST_DEBUG_DATA 0x02
#define RQST_DEBUG_LABEL 0x04
#define RQST_COMPASS_HEADING 0x08
#define RQST_EXTERN_CTRL 0x10
#define RQST_DISPLAY_DATA 0x20
 
 
uint8_t RequestFlags = 0x00;
uint8_t RequestDebugLabel = 0;
uint8_t ConfirmFrame = 0;
 
uint8_t DisplayLine = 0;
 
uint16_t PC_Connected = 0;
uint16_t FC_Connected = 0;
 
 
DebugOut_t DebugOut;
ExternData_t ExternData;
ExternControl_t ExternControl;
UART_VersionInfo_t UART_VersionInfo;
 
uint16_t DebugData_Timer;
uint16_t DebugData_Interval = 500;
 
const prog_uint8_t ANALOG_LABEL[32][16] =
{
//1234567890123456
"Magnet X ", //0
"Magnet Y ",
"Magnet Z ",
"RawMagnet X ",
"RawMagnet Y ",
"RawMagnet Z ", //5
"Attitude Nick ",
"Attitude Roll ",
"Magnet X Offset ",
"Magnet X Range ",
"Magnet Y Offset ", //10
"Magnet Y Range ",
"Magnet Z Offset ",
"Magnet Z Range ",
"Calstate ",
"Heading ", //15
"User0 ",
"User1 ",
"Acc X ",
"Acc Y ",
"Acc Z ", //20
"RawAcc X ",
"RawAcc Y ",
"RawAcc Z ",
"Acc X Offset ",
"Acc Y Offset ", //25
"Acc Z Offset ",
"Heading X ",
"Heading Y ",
"Attitude Source ",
"I2C Error ", //30
"I2C Okay "
};
 
 
/****************************************************************/
/* Initialization of the USART0 */
/****************************************************************/
void USART0_Init (void)
{
uint8_t sreg = SREG;
uint16_t ubrr = (uint16_t) ((uint32_t) F_CPU/(8 * BAUD_RATE) - 1);
 
// disable all interrupts before configuration
cli();
 
// disable RX-Interrupt
UCSR0B &= ~(1 << RXCIE0);
// disable TX-Interrupt
UCSR0B &= ~(1 << TXCIE0);
 
// set direction of RXD0 and TXD0 pins
 
// set RXD0 (PD0) as an input pin tristate
DDRD &= ~(1 << DDD0);
PORTD &= ~(1 << PORTD0);
// set TXD0 (PD1) as an output pin
DDRD |= (1 << DDD1);
PORTD &= ~(1 << PORTD1);
 
 
// USART0 Baud Rate Register
// set clock divider
UBRR0H = (uint8_t)(ubrr >> 8);
UBRR0L = (uint8_t)ubrr;
 
// USART0 Control and Status Register A, B, C
 
// enable double speed operation
UCSR0A |= (1 << U2X0);
 
// set asynchronous mode
UCSR0C &= ~(1 << UMSEL01);
UCSR0C &= ~(1 << UMSEL00);
// no parity
UCSR0C &= ~(1 << UPM01);
UCSR0C &= ~(1 << UPM00);
// 1 stop bit
UCSR0C &= ~(1 << USBS0);
// 8-bit
UCSR0B &= ~(1 << UCSZ02);
UCSR0C |= (1 << UCSZ01);
UCSR0C |= (1 << UCSZ00);
 
// enable receiver and transmitter
UCSR0B |= (1 << RXEN0);
UCSR0B |= (1 << TXEN0);
 
// flush receive buffer
while ( UCSR0A & (1<<RXC0) ) UDR0;
 
// enable RX-Interrupt
UCSR0B |= (1 << RXCIE0);
// enable TX-Interrupt
UCSR0B |= (1 << TXCIE0);
 
// initialize the debug timer
DebugData_Timer = SetDelay(DebugData_Interval);
 
// unlock rxd_buffer
rxd_buffer_locked = FALSE;
pRxData = 0;
RxDataLen = 0;
 
// no bytes to send
txd_complete = TRUE;
 
 
UART_VersionInfo.SWMajor = VERSION_MAJOR;
UART_VersionInfo.SWMinor = VERSION_MINOR;
UART_VersionInfo.SWPatch = VERSION_PATCH;
UART_VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR;
UART_VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR;
 
// send version info at startup
USART0_putchar ('\n');
USART0_putchar ('C');
USART0_putchar ('P');
USART0_putchar (':');
USART0_putchar ('V');
USART0_putchar ('0' + VERSION_MAJOR);
USART0_putchar ('.');
USART0_putchar ('0' + VERSION_MINOR/10);
USART0_putchar ('0' + VERSION_MINOR%10);
USART0_putchar ('a' + VERSION_PATCH);
USART0_putchar ('\n');
 
// restore global interrupt flags
SREG = sreg;
}
 
// ---------------------------------------------------------------------------------
void USART0_EnableTXD(void)
{
DDRD |= (1<<DDD1); // set TXD pin as output
PORTD &= ~(1 << PORTD1);
UCSR0B |= (1 << TXEN0); // enable TX in USART
//changing the interrupt flag yields to strange effects
//UCSR0B |= (1 << TXCIE0); // enable TX-Interrupt
}
 
// ---------------------------------------------------------------------------------
void USART0_DisableTXD(void)
{
while(!txd_complete){ };
//changing the interrupt flag yields to strange effects
//UCSR0B &= ~(1 << TXCIE0); // disable TX-Interrupt
UCSR0B &= ~(1 << TXEN0); // disable TX in USART
DDRD &= ~(1<<DDD1); // set TXD pin as input
PORTD &= ~(1 << PORTD1);
}
 
/****************************************************************/
/* USART0 transmitter ISR */
/****************************************************************/
ISR(USART_TX_vect)
{
static uint16_t ptr_txd_buffer = 0;
uint8_t tmp_tx;
if(!txd_complete) // transmission not completed
{
ptr_txd_buffer++; // die [0] wurde schon gesendet
tmp_tx = txd_buffer[ptr_txd_buffer];
// if terminating character or end of txd buffer was reached
if((tmp_tx == '\r') || (ptr_txd_buffer == TXD_BUFFER_LEN))
{
ptr_txd_buffer = 0; // reset txd pointer
txd_complete = TRUE; // stop transmission
}
UDR0 = tmp_tx; // send current byte will trigger this ISR again
}
// transmission completed
else ptr_txd_buffer = 0;
}
 
/****************************************************************/
/* USART0 receiver ISR */
/****************************************************************/
ISR(USART_RX_vect)
{
static uint16_t crc;
uint8_t crc1, crc2;
uint8_t c;
static uint8_t ptr_rxd_buffer = 0;
 
c = UDR0; // catch the received byte
 
if(rxd_buffer_locked) return; // if rxd buffer is locked immediately return
 
// the rxd buffer is unlocked
if((ptr_rxd_buffer == 0) && (c == '#')) // if rxd buffer is empty and syncronisation character is received
{
rxd_buffer[ptr_rxd_buffer++] = c; // copy 1st byte to buffer
crc = c; // init crc
}
#if 0
else if (ptr_rxd_buffer == 1) // handle address
{
rxd_buffer[ptr_rxd_buffer++] = c; // copy byte to rxd buffer
crc += c; // update crc
}
#endif
else if (ptr_rxd_buffer < RXD_BUFFER_LEN) // collect incomming bytes
{
if(c != '\r') // no termination character
{
rxd_buffer[ptr_rxd_buffer++] = c; // copy byte to rxd buffer
crc += c; // update crc
}
else // termination character was received
{
// the last 2 bytes are no subject for checksum calculation
// they are the checksum itself
crc -= rxd_buffer[ptr_rxd_buffer-2];
crc -= rxd_buffer[ptr_rxd_buffer-1];
// calculate checksum from transmitted data
crc %= 4096;
crc1 = '=' + crc / 64;
crc2 = '=' + crc % 64;
// compare checksum to transmitted checksum bytes
if((crc1 == rxd_buffer[ptr_rxd_buffer-2]) && (crc2 == rxd_buffer[ptr_rxd_buffer-1]))
{ // checksum valid
rxd_buffer[ptr_rxd_buffer] = '\r'; // set termination character
ReceivedBytes = ptr_rxd_buffer + 1;// store number of received bytes
rxd_buffer_locked = TRUE; // lock the rxd buffer
// if 2nd byte is an 'R' enable watchdog that will result in an reset
if(rxd_buffer[2] == 'R') {wdt_enable(WDTO_250MS);} // Reset-Commando
}
else
{ // checksum invalid
rxd_buffer_locked = FALSE; // unlock rxd buffer
}
ptr_rxd_buffer = 0; // reset rxd buffer pointer
}
}
else // rxd buffer overrun
{
ptr_rxd_buffer = 0; // reset rxd buffer
rxd_buffer_locked = FALSE; // unlock rxd buffer
}
}
 
 
// --------------------------------------------------------------------------
void AddCRC(uint16_t datalen)
{
uint16_t tmpCRC = 0, i;
for(i = 0; i < datalen; i++)
{
tmpCRC += txd_buffer[i];
}
tmpCRC %= 4096;
txd_buffer[i++] = '=' + tmpCRC / 64;
txd_buffer[i++] = '=' + tmpCRC % 64;
txd_buffer[i++] = '\r';
txd_complete = FALSE;
UDR0 = txd_buffer[0]; // initiates the transmission (continued in the TXD ISR)
}
 
 
 
// --------------------------------------------------------------------------
void SendOutData(uint8_t cmd, uint8_t address, uint8_t numofbuffers, ...) // uint8_t *pdata, uint8_t len, ...
{
va_list ap;
uint16_t pt = 0;
uint8_t a,b,c;
uint8_t ptr = 0;
 
uint8_t *pdata = 0;
int len = 0;
 
txd_buffer[pt++] = '#'; // Start character
txd_buffer[pt++] = 'a' + address; // Address (a=0; b=1,...)
txd_buffer[pt++] = cmd; // Command
 
va_start(ap, numofbuffers);
if(numofbuffers)
{
pdata = va_arg(ap, uint8_t*);
len = va_arg(ap, int);
ptr = 0;
numofbuffers--;
}
 
while(len)
{
if(len)
{
a = pdata[ptr++];
len--;
if((!len) && numofbuffers)
{
pdata = va_arg(ap, uint8_t*);
len = va_arg(ap, int);
ptr = 0;
numofbuffers--;
}
}
else a = 0;
if(len)
{
b = pdata[ptr++];
len--;
if((!len) && numofbuffers)
{
pdata = va_arg(ap, uint8_t*);
len = va_arg(ap, int);
ptr = 0;
numofbuffers--;
}
}
else b = 0;
if(len)
{
c = pdata[ptr++];
len--;
if((!len) && numofbuffers)
{
pdata = va_arg(ap, uint8_t*);
len = va_arg(ap, int);
ptr = 0;
numofbuffers--;
}
}
else c = 0;
txd_buffer[pt++] = '=' + (a >> 2);
txd_buffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4));
txd_buffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6));
txd_buffer[pt++] = '=' + ( c & 0x3f);
}
va_end(ap);
AddCRC(pt); // add checksum after data block and initates the transmission
}
 
 
// --------------------------------------------------------------------------
void Decode64(void)
{
uint8_t a,b,c,d;
uint8_t x,y,z;
uint8_t ptrIn = 3;
uint8_t ptrOut = 3;
uint8_t len = ReceivedBytes - 6;
 
while(len)
{
a = rxd_buffer[ptrIn++] - '=';
b = rxd_buffer[ptrIn++] - '=';
c = rxd_buffer[ptrIn++] - '=';
d = rxd_buffer[ptrIn++] - '=';
//if(ptrIn > ReceivedBytes - 3) break;
 
x = (a << 2) | (b >> 4);
y = ((b & 0x0f) << 4) | (c >> 2);
z = ((c & 0x03) << 6) | d;
 
if(len--) rxd_buffer[ptrOut++] = x; else break;
if(len--) rxd_buffer[ptrOut++] = y; else break;
if(len--) rxd_buffer[ptrOut++] = z; else break;
}
pRxData = &rxd_buffer[3];
RxDataLen = ptrOut - 3;
}
 
 
 
// --------------------------------------------------------------------------
int16_t USART0_putchar (int8_t c)
{
// if tx is not enabled return immediatly
if(!(UCSR0B & (1 << TXEN0))) return (0);
if (c == '\n') USART0_putchar('\r');
// wait until previous character was send
loop_until_bit_is_set(UCSR0A, UDRE0);
// send character
UDR0 = c;
return (0);
}
 
 
// --------------------------------------------------------------------------
void USART0_ProcessRxData(void)
{
// if data in the rxd buffer are not locked immediately return
if(!rxd_buffer_locked) return;
 
Decode64(); // decode data block in rxd_buffer
 
switch(rxd_buffer[1]-'a') // check Slave Address
{
case MK3MAG_ADDRESS:
 
switch(rxd_buffer[2]) // check for CmdID
{
case 'w': // old style
case 'k': // Attitude info from FC
memcpy(&ExternData, (uint8_t*)pRxData, sizeof(ExternData));
RequestFlags |= RQST_COMPASS_HEADING;
AttitudeSource = ATTITUDE_SOURCE_UART;
Orientation = ExternData.Orientation;
FC_Connected = 255;
break;
 
default:
// unsupported command
break;
} // case MK3MAG_ADDRESS:
 
default: // any Slave Address
 
switch(rxd_buffer[2]) // check for CmdID
{
case 'b': // extern control
memcpy(&ExternControl, (uint8_t*)pRxData, sizeof(ExternControl));
#define KEY1 0x01
#define KEY2 0x02
#define KEY3 0x04
#define KEY4 0x08
#define KEY5 0x10
// use right arrow at display for switching the calstate
if(ExternControl.RemoteButtons & KEY2)
{
ExternData.CalState++;
if(ExternData.CalState == 6) ExternData.CalState = 0;
}
ConfirmFrame = ExternControl.Frame;
PC_Connected = 2000;
break;
 
case 'd': // request for the debug data
DebugData_Interval = (uint16_t) pRxData[0] * 10;
if(DebugData_Interval>0) RequestFlags |= RQST_DEBUG_DATA;
PC_Connected = 2000;
break;
 
case 'v': // request version and board release
RequestFlags |= RQST_VERSION_INFO;
PC_Connected = 2000;
break;
 
case 'h': // request display data
RemoteKeys |= pRxData[0];
if(RemoteKeys) DisplayLine = 0;
RequestFlags |= RQST_DISPLAY_DATA;
PC_Connected = 2000;
break;
 
case 'a':// Labels of the Analog Debug outputs
RequestDebugLabel = pRxData[0];
RequestFlags |= RQST_DEBUG_LABEL;
PC_Connected = 2000;
break;
 
case 'g':// get extern control data
RequestFlags |= RQST_EXTERN_CTRL;
PC_Connected = 2000;
break;
 
default:
// unsupported command
break;
}
break; // default:
}
// unlock the rxd buffer after processing
pRxData = 0;
RxDataLen = 0;
rxd_buffer_locked = FALSE;
}
 
 
 
//---------------------------------------------------------------------------------------------
void USART0_TransmitTxData(void)
{
if(!(UCSR0B & (1 << TXEN0))) return;
 
if(!txd_complete) return;
 
if((RequestFlags & RQST_DEBUG_LABEL) && txd_complete)
{
uint8_t label[16];
memcpy_P(label, ANALOG_LABEL[RequestDebugLabel], 16); // read lable from flash to sram buffer
SendOutData('A', MK3MAG_ADDRESS, 2, (uint8_t *)&RequestDebugLabel, sizeof(RequestDebugLabel), label, 16);
RequestDebugLabel = 0xFF;
RequestFlags &= ~RQST_DEBUG_LABEL;
}
else if(ConfirmFrame && txd_complete)
{
SendOutData('B', MK3MAG_ADDRESS, 1, (uint8_t *) &ConfirmFrame, sizeof(ConfirmFrame));
ConfirmFrame = 0;
}
else if(( ((DebugData_Interval > 0) && CheckDelay(DebugData_Timer)) || (RequestFlags & RQST_DEBUG_DATA)) && txd_complete)
{
SetDebugValues();
SendOutData('D', MK3MAG_ADDRESS, 1, (uint8_t *) &DebugOut, sizeof(DebugOut));
DebugData_Timer = SetDelay(DebugData_Interval);
RequestFlags &= ~RQST_DEBUG_DATA;
}
else if((RequestFlags & RQST_DISPLAY_DATA) && txd_complete)
{
LCD_PrintMenu();
SendOutData('H', FC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), &DisplayBuff[DisplayLine * 20], 20);
DisplayLine++;
if(DisplayLine >= 4) DisplayLine = 0;
RequestFlags &= ~RQST_DISPLAY_DATA;
}
else if((RequestFlags & RQST_EXTERN_CTRL) && txd_complete)
{
SendOutData('G', MK3MAG_ADDRESS, 1, (uint8_t *) &ExternControl,sizeof(ExternControl));
RequestFlags &= ~RQST_EXTERN_CTRL;
}
else if((RequestFlags & RQST_COMPASS_HEADING) && txd_complete)
{
SendOutData('K', FC_ADDRESS, 1, (uint8_t *) &Heading, sizeof(Heading)); // send compass heading to FC
RequestFlags &= ~RQST_COMPASS_HEADING;
}
else if((RequestFlags & RQST_VERSION_INFO) && txd_complete)
{
SendOutData('V', MK3MAG_ADDRESS, 1, (uint8_t *) &UART_VersionInfo, sizeof(UART_VersionInfo));
RequestFlags &= ~RQST_VERSION_INFO;
}
}
 
 
void USART0_Print(int8_t *msg)
{
uint8_t i = 0;
while(msg[i] != 0)
{
USART0_putchar(msg[i++]);
}
}
/tags/V0.22c/uart.h
0,0 → 1,76
#ifndef _UART_H_
#define _UART_H_
 
#include <inttypes.h>
 
#define NICK 0
#define ROLL 1
 
 
#define BAUD_RATE 57600
 
 
extern uint16_t DebugData_Timer;
 
 
void USART0_Init (void);
void USART0_EnableTXD(void);
void USART0_DisableTXD(void);
void USART0_TransmitTxData(void);
void USART0_ProcessRxData(void);
int16_t USART0_putchar(int8_t c);
void USART0_Print(int8_t *msg);
 
 
 
typedef struct
{
uint8_t Digital[2];
uint16_t Analog[32]; // Debugvalues
} DebugOut_t;
 
extern DebugOut_t DebugOut;
 
 
 
typedef struct
{
int16_t Attitude[2]; // nick and roll angle in 0.1 deg
uint8_t UserParam[2];
uint8_t CalState;
uint8_t Orientation;
} ExternData_t;
 
extern ExternData_t ExternData;
 
typedef struct
{
uint8_t Digital[2];
uint8_t RemoteButtons;
int8_t Nick;
int8_t Roll;
int8_t Yaw;
uint8_t Gas;
int8_t Height;
uint8_t free;
uint8_t Frame;
uint8_t Config;
} ExternControl_t;
 
extern ExternControl_t ExternControl;
 
 
typedef struct
{
uint8_t SWMajor;
uint8_t SWMinor;
uint8_t ProtoMajor;
uint8_t ProtoMinor;
uint8_t SWPatch;
uint8_t Reserved[5];
} UART_VersionInfo_t;
 
extern uint16_t PC_Connected;
extern uint16_t FC_Connected;
 
#endif //_UART_H_
/tags/V0.22c
Property changes:
Added: tsvn:logminsize
+8
\ No newline at end of property