quinta-feira, 17 de dezembro de 2015

Dispositivos I2C

Mais Dispositivos I2C

Implementei junto ao programa de edição de memórias EEPROM com utilização da placa MCLAB2, a possibilidade de manipular mais dois interessantes circuitos integrados com comunicação I2C. Um deles é o PCF8574(A) da Philips que é um extensor de portas de E/S quase bidirecional, o que o torna muito útil quando se faltam portas para um microcontrolador. O outro é um sensor de campo magnético bem sensível o HMC5883L da Honeywell, muito usado em bússolas eletrônicas e com capacidade de medição de campos magnéticos em 3 eixos (x, y, z). 
Em resumo, o integrado PCF8574 possui 8 portas de E/S que podem ser escritas ou lidas através de comunicação serial I2C, além de possuir um pino de sinalização de interrupção e 3 linhas de endereçamento para identificar o ci se forem usados vários dispositivos no barramento I2C. Assim ele funciona como um conversor serial-paralelo e vice-e-versa. Como ele tem boa capacidade de corrente nas portas (25mA tanto suprindo como drenando) elas são capazes de acionar diversos dispositivos, como por exemplo, leds, muito facilmente. A velocidade para o clock do I2C deve ser de 100kHz. A diferença entre as versões 8574 e 8574A é apenas no endereçamento do dispositivo escravo.

A seguir a pinagem e o diagrama de blocos do PCF8574.


  
No diagrama de tempos do fluxo serial, demonstra qual deve ser o byte de controle enviado, sendo que para o PCF8574, o endereço escravo deve ter os 4 bits mais significativos como 0100 (e 0111 para o 8574A), seguido dos 3 bits de endereçamento de dispositivo e finalmente o bit0 significando escrita (0) ou leitura (1).  

Aqui o fluxo para escrita:


O fluxo para leitura:

Abaixo o esquema elétrico para a conexão do PIC 16F877 com o PCF8574:


No firmware, o PCF8574 passa a ser a opção de seleção número 11 no menu de seleção de dispositivos e o PCF8574A a opção 12. 
Pode-se fazer então a leitura das portas do PCF8574, ou a escrita das portas, onde se entra com o endereço do dispositivo no barramento I2C e em seguida o valor a ser escrito nas 8 portas.


O circuito integrado HMC5883L fornece a medição de campo magnético em 3 eixos, em dois registradores de 2 bytes cada, mas com 12 bits de valor, que representa uma resolução de 2 mili gauss e capacidade de medir até 8 gauss. Esse dispositivo usa tecnologia AMR (anisotropic magneto resistive). Como ele é um ci em encapsulamento smd, geralmente é mais prático utilizá-los através de pequenos módulos, em que há apenas acesso a 5 pinos (alimentação e barramento I2C).
A seguir o diagrama de blocos e interligação com o microcontrolador:


E o esquema completo:


No firmware, o HMC5883L passa a ser a opção 13 no menu de dispositivos. Como a utilização dele é apenas de leitura, na opção de leitura o display passa a apresentar de pronto os valores medidos nos 3 eixos, com polaridade N (negativo) e P (positivo).
A saída se dá pelo botão número 4.

Forneço aqui os códigos hexadecimais a serem gravados no PIC:

:10000000B2018C29B216B21EB212B2190B28B21567
:100010004420031832280830A3005920A20DA30B56
:100020000D28B21E3D2063205F20B21A32203720F7
:10003000220803108729B216B21EB21232192528DF
:10004000FE39B300321503108729321A2D28A60075
:10005000321644200318322826084C200318322870
:10006000B21E87293D20632032113212B2113608A8
:100070008400340884178004432836088400340937
:100080008005841780058729372063208B213D2038
:100090005F203308B2190138A2000830A300A20D76
:1000A00003183720031C3D2063205F20A30B4F283B
:1000B000372063203608840034080005FF3E3708E7
:1000C0008400350940283708840035083A28040898
:1000D000A70089100910091083168910091009104A
:1000E000880183122708B21890283A30A100FC300A
:1000F00012213330A600A3201030A1006830122155
:10010000A32064301121A32038308F200C308F20A1
:1001100001308F2006308F20B21427089028321427
:10012000A600321C9E280910033C031CA328A32010
:100130000730A100D0301221031408003214FE3C15
:100140000319872909148914260888003210891098
:100150003230112103140800B31329080319B3170F
:100160001030A8000301A40DA50D03180130EC20E8
:100170002808031DB2280800B31329080319B31770
:100180000430A800250EC9202508C920240EC92046
:1001900024080F39F63E0318073E0A3EEC28B31335
:1001A00029080319B3170530A8002730A300103021
:1001B000E5200330A300E830E520A3016430E5200A
:1001C000A3010A30E5202408EC28A2002508A1009C
:1001D0002408A00050212008A000A8030319B3138D
:1001E00029080319F6282802031808002008031D0F
:1001F000B313B31B0800303E822983178001840AA1
:10020000FF3E031DFE288729A301A200FF30A2079D
:10021000031CA307031C87290330A100DF30122130
:100220000629A101E83EA000A109FC30031C1B29FE
:10023000A00703181829A0076400A10F1829201887
:100240002129A01C2529000025290800A101A301BE
:10025000A20001303529A20006303529A101A301F1
:10026000A20004303529A2000530A800230821028D
:10027000031D3C2922082002043003180130031911
:1002800002302805031DFF3087290038031DFF3089
:100290000405031DFF3087290404031DFF3087294F
:1002A000A501A4011030A600210DA40DA50D220862
:1002B000A4022308031C230FA502031866292208A1
:1002C000A40723080318230FA5070310A00DA10DF1
:1002D000A60B5429200887291030A800A101A001ED
:1002E000A70CA60C031C7A292208A00723080318D0
:1002F000230FA107A10CA00CA50CA40CA80B70291E
:1003000024088729840031088A003008820083137A
:1003100003138312640008008316DF3085000F305A
:100320008600913087008801890106309F000730E0
:100330009C00831207112030840060308A01FE2067
:10034000A030840050308A01FE20103084006030DC
:100350008A01FD209030840060308A01FD20FE304B
:100360008A01682001308A01682050308A016820A3
:100370006C308A01682061308A01682063308A010C
:10038000682061308A01682020308A0168204D3061
:100390008A01682043308A0168204C308A01682035
:1003A00041308A01682042308A01682032308A0157
:1003B000682020308A01682020308A01682020309F
:1003C0008A01682020308A016820FE308A01682076
:1003D000C0308A0168204C308A01682065308A016B
:1003E00068202F308A01682067308A0168207230C7
:1003F0008A01682061308A01682076308A0168208D
:1004000061308A01682020308A01682049308A01E1
:10041000682032308A01682043308A016820203009
:100420008A01682020308A01682020308A016820F3
:10043000FE308A0168200F308A0168200330A30053
:10044000E8308A010521FE308A01682001308A01E6
:10045000682031308A0168202D308A01682073308D
:100460008A01682065308A0168206C308A01682022
:1004700020308A01682064308A01682065308A0152
:10048000682076308A01682020308A016820323066
:100490008A0168202D308A01682072308A01682024
:1004A00065308A01682061308A01682064308A01E1
:1004B0006820FE308A016820C0308A01682033300D
:1004C0008A0168202D308A01682077308A016820EF
:1004D00072308A01682069308A01682074308A018C
:1004E000682065308A01682020308A016820343015
:1004F0008A0168202D308A01682065308A016820D1
:1005000072308A01682061308A01682073308A0164
:10051000682065308A01682064008A110A12061872
:10052000992AFA308A0104210130CE008A110A1278
:10053000BC2A64008A110A128618A42AFA308A0199
:1005400004218A150A121A2B64008A110A1206194C
:10055000AF2AFA308A0104218A150A12162F640084
:100560008A110A128619BA2AFA308A0104218A11DC
:100570000A16C32A8A018C2AFE308A0168200130BB
:100580008A01682053308A01682065308A0168201A
:100590006C308A01682065308A01682063308A01E6
:1005A000682074308A01682020308A016820643015
:1005B0008A01682065308A01682076308A016820C7
:1005C00069308A01682063308A01682065308A01B9
:1005D00068203A308A01682020308A016820203063
:1005E0008A016820FE308A016820C0308A016820B4
:1005F0003D308A0168208A110A12342364008A116E
:100600000A120618122BFA308A010421CE03640064
:100610004E08003C8A110A12031D102B0D30CE002B
:100620008A01F22A64008A110A128618262BFA30EF
:100630008A010421CE0A64004E080E3C8A110A1277
:10064000031D242B0130CE008A01F22A64008A1196
:100650000A128619322B0130A3005E308A0105216F
:100660008A01AF298A01FE2A64004E08013C8A11E2
:100670000A12031D642BFE308A016820C0308A01F3
:1006800068203D308A01682032308A016820343089
:100690008A0168204C308A01682043308A01682032
:1006A00030308A01682031308A01682020308A0188
:1006B000682020308A01682020308A016820A0301C
:1006C000CB007F30BA00BB0164004E08023C8A11A7
:1006D0000A12031D942BFE308A016820C0308A0163
:1006E00068203D308A01682032308A016820343029
:1006F0008A0168204C308A01682043308A016820D2
:1007000030308A01682032308A01682020308A0126
:10071000682020308A01682020308A016820A030BB
:10072000CB00FF30BA00BB0164004E08033C8A11C5
:100730000A12031DC52BFE308A016820C0308A01D1
:1007400068203D308A01682032308A0168203430C8
:100750008A0168204C308A01682043308A01682071
:1007600030308A01682034308A01682020308A01C4
:10077000682020308A01682020308A016820A0305B
:10078000CB00FF30BA000130BB0064004E08043CCF
:100790008A110A12031DF62BFE308A016820C03030
:1007A0008A0168203D308A01682032308A01682041
:1007B00034308A0168204C308A01682043308A0135
:1007C000682030308A01682038308A016820203063
:1007D0008A01682020308A01682020308A01682040
:1007E000A030CB00FF30BA000330BB0064004E08DD
:1007F000053C8A110A12031D272CFE308A0168204D
:10080000C0308A0168203D308A01682032308A0178
:10081000682034308A0168204C308A0168204330D7
:100820008A01682031308A01682036308A016820C8
:1008300020308A01682020308A01682020308A0117
:100840006820A030CB00FF30BA000730BB00640046
:100850004E08063C8A110A12031D582CFE308A01EC
:100860006820C0308A0168203D308A01682032301B
:100870008A01682034308A0168204C308A0168205F
:1008800043308A01682033308A01682032308A017F
:10089000682020308A01682020308A0168202030BA
:1008A0008A016820A030CB00FF30BA000F30BB00B7
:1008B00064004E08073C8A110A12031D892CA030DF
:1008C000CB00FE308A016820C0308A0168203D30AC
:1008D0008A01682032308A01682034308A01682019
:1008E0004C308A01682043308A01682036308A0102
:1008F000682034308A01682020308A016820203046
:100900008A01682020308A016820FF30BA001F3039
:10091000BB0064004E08083C8A110A12031DB82C63
:10092000FE308A016820C0308A0168203D308A018B
:10093000682032308A01682034308A0168204C30C7
:100940008A01682043308A01682031308A0168209A
:1009500032308A01682038308A01682020308A01CC
:10096000682020308A016820FF30BA003F30BB0089
:1009700064004E08093C8A110A12031DE72CFE3060
:100980008A016820C0308A0168203D308A016820D1
:1009900032308A01682034308A0168204C308A0164
:1009A000682043308A01682032308A01682035305F
:1009B0008A01682036308A01682020308A01682048
:1009C00020308A016820FF30BA007F30BB0064000D
:1009D0004E080A3C8A110A12031D162DFE308A01A8
:1009E0006820C0308A0168203D308A01682032309A
:1009F0008A01682034308A0168204C308A016820DE
:100A000043308A01682035308A01682031308A01FC
:100A1000682032308A01682020308A016820203026
:100A20008A016820FF30BA00FF30BB0064004E0826
:100A30000B3C8A110A12031D432DFE308A016820E7
:100A4000C0308A0168203D308A01682050308A0118
:100A5000682043308A01682046308A016820383097
:100A60008A01682035308A01682037308A01682081
:100A700034308A01682020308A01682020308A01C1
:100A800068204030CB0064004E080C3C8A110A12EA
:100A9000031D702DFE308A016820C0308A01682055
:100AA0003D308A01682050308A01682043308A0135
:100AB000682046308A01682038308A016820353045
:100AC0008A01682037308A01682034308A01682022
:100AD00041308A01682020308A0168207030CB00C4
:100AE00064004E080D3C8A110A12031D9B2DFE3036
:100AF0008A016820C0308A0168203D308A01682060
:100B000048308A0168204D308A01682043308A01CC
:100B1000682035308A01682038308A0168203830F2
:100B20008A01682033308A0168204C308A016820AD
:100B300020308A0168200800FE308A0168200F30CA
:100B40008A016820FE308A01682001308A0168200D
:100B500045308A0168206E308A01682074308A012D
:100B6000682065308A01682072308A016820203050
:100B70008A01682061308A01682064308A01682017
:100B800064308A01682072308A01682065308A01E9
:100B9000682073308A01682073308A0168203A30F7
:100BA0008A01682020308A01682020308A0168206C
:100BB00064000B304E028A110A120318E22D8A11CA
:100BC0000A12592ECA01FE308A016820C0308A01FB
:100BD00068203D308A016820A9014A08A400A501C7
:100BE0006730B000B1018A01CF20FE308A01682051
:100BF000C1308A01682064008A110A120618252E65
:100C0000FA308A010421CA0364004A08FF3C8A11B1
:100C10000A12031D0D2E0730CA00FE308A0168201B
:100C2000C0308A0168203D308A016820A9014A0845
:100C3000A400A5016730B000B1018A01CF20FE30C9
:100C40008A016820C1308A01682064008A110A1272
:100C500086184E2EFA308A010421CA0A64004A0816
:100C6000083C8A110A12031D362ECA01FE308A0181
:100C70006820C0308A0168203D308A016820A901BF
:100C80004A08A400A5016730B000B1018A01CF2055
:100C9000FE308A016820C1308A01682064008A1110
:100CA0000A128619572EFA308A01042108008A0197
:100CB000FB2DA6011030A7005408A200A3018A0151
:100CC0006C21BC002508BD00A6010130A700530817
:100CD000A200A3018A016C21BE002508BF003C08C8
:100CE000BE073D080318013EBF071030A600A7014C
:100CF0005208A200A3018A016C21C0002508C1008E
:100D00003E08C0073F080318013EC10751084007CD
:100D1000B80041080318013EB900FE308A0168207E
:100D2000C0308A0168203D308A0168200430A90063
:100D30003808A4003908A5006730B000B1018A0165
:100D4000BC2020308A0168200530A9003808A400A2
:100D50003908A5006730B000B1018A01CF20FE300C
:100D60008A016820C1308A01682064008A110A1251
:100D70000618232FFA308A010421D4036400540892
:100D8000FF3C8A110A12031DC72E0F30D400A601A2
:100D90001030A7005408A200A3018A016C21BC00F6
:100DA0002508BD00A6010130A7005308A200A30139
:100DB0008A016C21BE002508BF003C08BE073D0823
:100DC0000318013EBF071030A600A7015208A20079
:100DD000A3018A016C21C0002508C1003E08C0079C
:100DE0003F080318013EC10751084007B8004108F9
:100DF0000318013EB900FE308A016820C0308A0124
:100E000068203D308A0168200430A9003808A40019
:100E10003908A5006730B000B1018A01BC2020303C
:100E20008A0168200530A9003808A4003908A50007
:100E30006730B000B1018A01CF20FE308A016820FE
:100E4000C1308A01682064008A110A128618902F26
:100E5000FA308A010421D40A64005408103C8A1133
:100E60000A12031D342FD401A6011030A700540824
:100E7000A200A3018A016C21BC002508BD00A601C7
:100E80000130A7005308A200A3018A016C21BE0013
:100E90002508BF003C08BE073D080318013EBF07F8
:100EA0001030A600A7015208A200A3018A016C21FC
:100EB000C0002508C1003E08C0073F080318013ED6
:100EC000C10751084007B80041080318013EB900A6
:100ED000FE308A016820C0308A0168203D308A01D6
:100EE00068200430A9003808A4003908A50067303C
:100EF000B000B1018A01BC2020308A016820053091
:100F0000A9003808A4003908A5006730B000B10175
:100F10008A01CF20FE308A016820C1308A01682012
:100F200064008A110A120619A12FFA308A010421DD
:100F3000FE308A01682014308A0168208A110A1262
:100F4000A32F8A01B52E64008A150A1206181128EB
:100F5000FA308A010421D30364005308FF3C8A114C
:100F60000A12031DB52F0F30D300A6011030A700C1
:100F70005408A200A3018A016C21BC002508BD0011
:100F8000A6010130A7005308A200A3018A016C2129
:100F9000BE002508BF003C08BE073D080318013EFF
:100FA000BF071030A600A7015208A200A3018A01C2
:100FB0006C21C0002508C1003E08C0073F08031887
:100FC000013EC10751084007B80041080318013E1F
:100FD000B900FE308A016820C0308A0168203D30A7
:100FE0008A0168200430A9003808A4003908A50047
:100FF0006730B000B1018A01BC2020308A0168202E
:101000000530A9003808A4003908A5006730B000F1
:10101000B1018A01CF20FE308A016820C2308A01E6
:10102000682064008A150A1286187E28FA308A0120
:101030000421D30A64005308103C8A150A12031DC8
:101040002228D301A6011030A7005408A200A30152
:101050008A016C21BC002508BD00A6010130A70053
:101060005308A200A3018A016C21BE002508BF001D
:101070003C08BE073D080318013EBF071030A6001C
:10108000A7015208A200A3018A016C21C000250813
:10109000C1003E08C0073F080318013EC1075108C0
:1010A0004007B80041080318013EB900FE308A012C
:1010B0006820C0308A0168203D308A0168200430F1
:1010C000A9003808A4003908A5006730B000B101B4
:1010D0008A01BC2020308A0168200530A900380828
:1010E000A4003908A5006730B000B1018A01CF2003
:1010F000FE308A016820C2308A01682064008A15A7
:101100000A1206198F28FA308A010421FE308A015A
:10111000682014308A0168208A150A1291288A01F1
:10112000A32F64008A150A120618FF28FA308A01D4
:101130000421D20364005208FF3C8A150A12031DE1
:10114000A3280F30D200A6011030A7005408A20037
:10115000A3018A016C21BC002508BD00A601013055
:10116000A7005308A200A3018A016C21BE00250834
:10117000BF003C08BE073D080318013EBF07103002
:10118000A600A7015208A200A3018A016C21C00099
:101190002508C1003E08C0073F080318013EC107EB
:1011A00051084007B80041080318013EB900FE305D
:1011B0008A016820C0308A0168203D308A01682099
:1011C0000430A9003808A4003908A5006730B00031
:1011D000B1018A01BC2020308A0168200530A900B5
:1011E0003808A4003908A5006730B000B1018A01B1
:1011F000CF20FE308A016820C3308A016820640055
:101200008A150A1286186C29FA308A010421D20A3A
:1012100064005208103C8A150A12031D1029D201DD
:10122000A6011030A7005408A200A3018A016C2176
:10123000BC002508BD00A6010130A7005308A2008C
:10124000A3018A016C21BE002508BF003C08BE072F
:101250003D080318013EBF071030A600A701520841
:10126000A200A3018A016C21C0002508C1003E082C
:10127000C0073F080318013EC10751084007B800E6
:1012800041080318013EB900FE308A016820C030D1
:101290008A0168203D308A0168200430A90038089E
:1012A000A4003908A5006730B000B1018A01BC2054
:1012B00020308A0168200530A9003808A4003908C8
:1012C000A5006730B000B1018A01CF20FE308A014D
:1012D0006820C3308A01682064008A150A12061942
:1012E0007D29FA308A010421FE308A0168201430F9
:1012F0008A0168208A150A1280298A150A12912803
:1013000064008A150A120618EE29FA308A010421AF
:10131000D10364005108FF3C8A150A12031D92296B
:101320000F30D100A6011030A7005408A200A3017D
:101330008A016C21BC002508BD00A6010130A70070
:101340005308A200A3018A016C21BE002508BF003A
:101350003C08BE073D080318013EBF071030A60039
:10136000A7015208A200A3018A016C21C000250830
:10137000C1003E08C0073F080318013EC1075108DD
:101380004007B80041080318013EB900FE308A0149
:101390006820C0308A0168203D308A01682004300E
:1013A000A9003808A4003908A5006730B000B101D1
:1013B0008A01BC2020308A0168200530A900380845
:1013C000A4003908A5006730B000B1018A01CF2020
:1013D000FE308A016820C4308A01682064008A15C2
:1013E0000A1286185B2AFA308A010421D10A6400A5
:1013F0005108103C8A150A12031DFF29D101A601CC
:101400001030A7005408A200A3018A016C21BC007F
:101410002508BD00A6010130A7005308A200A301C2
:101420008A016C21BE002508BF003C08BE073D08AC
:101430000318013EBF071030A600A7015208A20002
:10144000A3018A016C21C0002508C1003E08C00725
:101450003F080318013EC10751084007B800410882
:101460000318013EB900FE308A016820C0308A01AD
:1014700068203D308A0168200430A9003808A400A3
:101480003908A5006730B000B1018A01BC202030C6
:101490008A0168200530A9003808A4003908A50091
:1014A0006730B000B1018A01CF20FE308A01682088
:1014B000C4308A01682064008A150A1206196C2A51
:1014C000FA308A010421FE308A01682014308A0132
:1014D00068208A150A126F2A8A150A128029A60125
:1014E0001030A7005408A200A3018A016C21BC009F
:1014F0002508BD00A6010130A7005308A200A301E2
:101500008A016C21BE002508BF003C08BE073D08CB
:101510000318013EBF071030A600A7015208A20021
:10152000A3018A016C21C0002508C1003E08C00744
:101530003F080318013EC10751084007B8004108A1
:101540000318013EB9003808A0003908A1003B0883
:10155000A3003A088A012B218A150A12031D192BB0
:10156000FE308A01682001308A01682049308A01F2
:1015700068206E308A01682076308A0168206130E8
:101580008A0168206C308A01682069308A016820ED
:1015900064308A01682020308A01682061308A0125
:1015A000682064308A01682064308A0168207230C3
:1015B0008A01682065308A01682073308A016820BA
:1015C00073308A01682020308A016820FE308A0149
:1015D0006820C0308A0168204D308A01682061305F
:1015E0008A01682078308A01682020308A016820CA
:1015F00061308A01682064308A01682064308A0181
:10160000682072308A0168203D308A0168200530E8
:10161000A9003A08A4003B08A5006730B000B1015A
:101620008A01CF200B30A300B8308A0105218A013E
:101630009C2D080064000B304E028A150A12031814
:10164000242B8A150A12C52B64004E080D3C8A15FE
:101650000A12031D2E2B8A150A12022D8A019C25BF
:101660004B144A18CB144A1CCB10CA184B15CA1C71
:101670004B114A19CB154A1DCB110730B60010305B
:10168000B4000730B7000830B5004B088A011D20B0
:101690008A010220CD00FE308A01682001308A01D3
:1016A000682044308A01682061308A0168207430E3
:1016B0008A01682061308A01682020308A01682010
:1016C00066308A01682072308A0168206F308A0192
:1016D00068206D308A01682020308A0168207030CF
:1016E0008A0168206F308A01682072308A01682080
:1016F00074308A01682073308A0168203A308A0188
:101700006820FE308A016820C0308A016820643079
:101710008A01682061308A01682074308A0168205B
:1017200061308A0168203D308A0168200230A900BA
:101730004D08A400A5016730B000B1018A01BC20AA
:1017400020308A0168200830A9004D08A400A501B6
:101750006730B000B1018A01AC2064008A150A121A
:101760008619B72BFA308A0104218A01AF29640057
:101770008A150A120619C22BFA308A0104218A1529
:101780000A12302B8A150A12AD2B8A019C254B14A4
:10179000FE308A01682001308A01682061308A01A8
:1017A000682064308A01682064308A0168207230C1
:1017B0008A0168203D308A0168200430A900380879
:1017C000A4003908A5006730B000B1018A01BC202F
:1017D00020308A0168200530A9003808A4003908A3
:1017E000A5006730B000B1018A01CF20640003304A
:1017F0004E028A150A1203180E2C0730B60010305C
:10180000B4000730B7000830B5004B088A011D202E
:1018100038088A011D208A010220D6004E08033CA8
:10182000031DFF30FF3ABC004E08043C031DFF308F
:10183000FF3ABE003C0884003E088A014C21BE00ED
:10184000BF004E08053C031DFF30FF3AC0003E08B4
:101850003F04840040088A014C21C000C10064009C
:10186000400841048A150A120319532C3918CB1465
:10187000391CCB10B9184B15B91C4B113919CB15A4
:10188000391DCB110730B6001030B4000730B70057
:101890000830B5004B088A011D2038088A011D2038
:1018A0008A010220D6004E08A00005308A012621B8
:1018B000BC004E08A0000B308A012E21BE003C085F
:1018C00084003E088A014521BE00BF0064003E0836
:1018D0003F048A150A120319812C0730B600103014
:1018E000B4000730B7000830B5004B088A011D204E
:1018F00039088A011D2038088A011D208A0102202A
:10190000D600FE308A016820C0308A016820643029
:101910008A01682061308A01682074308A01682059
:1019200061308A0168203D308A0168200230A900B8
:101930005608A400A5016730B000B1018A01BC209F
:1019400020308A0168200330A9005608A400A501B0
:101950006730B000B1018A01CF2064008A150A12F5
:101960000618D62CFA308A0104210130B802003062
:10197000031C013EB902FF30A000FF30A10039086E
:10198000A30038088A0133218A150A12031DD32CBB
:1019900064000A304E028A150A120318D32C3A0842
:1019A000B8003B08B9008A150A12C72B64008A15D3
:1019B0000A128618F32CFA308A010421B80A031996
:1019C000B90A3808A0003908A1003B08A3003A086A
:1019D0008A012B218A150A12031DF02CB801B901C6
:1019E0008A150A12C72B64008A150A128619FF2C61
:1019F0000130A3005E308A0105218A01AF298A15D2
:101A00000A12AD2C0A308A010421B801B90107304D
:101A1000B6001030B4000730B7000830B5003C30D5
:101A20008A011D2038088A011D2070308A011B2080
:101A300064308A0104210130B800B9010730B600D2
:101A40001030B4000730B7000830B5003C308A01D0
:101A50001D2038088A011D20E0308A011B206430D7
:101A60008A0104210230B800B9010730B6001030F5
:101A7000B4000730B7000830B5003C308A011D20A3
:101A800038088A011D2000308A011B20FE308A019F
:101A9000682001308A0168204D308A016820653055
:101AA0008A01682064308A01682069308A016820D0
:101AB00064308A0168206F308A01682072308A01A0
:101AC000682020308A0168204D308A01682061300A
:101AD0008A01682067308A0168206E308A01682098
:101AE00065308A01682074308A01682069308A0173
:101AF000682063308A0168200130A300F4308A0135
:101B000005210330B800B9010730B6001030B40029
:101B10000730B7000830B5003D308A011D20380875
:101B20008A011D208A010220C30014308A01042189
:101B30000430B800B9010730B6001030B4000730E7
:101B4000B7000830B5003D308A011D2038088A01F1
:101B50001D208A010220C20014308A0104210530B0
:101B6000B800B9010730B6001030B4000730B70034
:101B70000830B5003D308A011D2038088A011D203B
:101B80008A010220C70014308A0104210630B800FF
:101B9000B9010730B6001030B4000730B700083084
:101BA000B5003D308A011D2038088A011D208A01B8
:101BB0000220C60014308A0104210730B800B901A0
:101BC0000730B6001030B4000730B7000830B50059
:101BD0003D308A011D2038088A011D208A0102201B
:101BE000C90014308A0104210830B800B901073057
:101BF000B6001030B4000730B7000830B5003D30F3
:101C00008A011D2038088A011D208A010220C8008F
:101C10004208A0004308A1007F30A300FF308A01E2
:101C20002B218A150A12031D212E4208003CC200F6
:101C30004308031C013E003CC30055148A150A12D8
:101C4000222E55104608A0004708A1007F30A300AF
:101C5000FF308A012B218A150A12031D3B2E4608EC
:101C6000003CC6004708031C013E003CC700D514D9
:101C70008A150A123C2ED5104808A0004908A10078
:101C80007F30A300FF308A012B218A150A12031D21
:101C9000552E4808003CC8004908031C013E003C82
:101CA000C90055158A150A12562E551164008A1559
:101CB0000A125519742EFE308A01682001308A01FB
:101CC00068205A308A0168203D308A016820A901C5
:101CD0004808A4004908A5006730B000B1018A0196
:101CE000CF2050308A01682064008A150A12551DE1
:101CF000922EFE308A01682001308A0168205A3015
:101D00008A0168203D308A016820A9014808A400A2
:101D10004908A5006730B000B1018A01CF204E30DC
:101D20008A01682064008A150A125518B02EFE3008
:101D30008A016820C0308A01682058308A016820F2
:101D40003D308A016820A9014208A4004308A5008B
:101D50006730B000B1018A01CF2050308A0168207D
:101D600064008A150A12551CCE2EFE308A016820A6
:101D7000C0308A01682058308A0168203D308A01CD
:101D80006820A9014208A4004308A5006730B000FC
:101D9000B1018A01CF204E308A01682064008A1583
:101DA0000A12D518E92E20308A01682059308A019C
:101DB00068203D308A016820A9014608A400470830
:101DC000A5006730B000B1018A01CF2050308A01F0
:101DD000682064008A150A12D51C042F20308A015D
:101DE000682059308A0168203D308A016820A901A5
:101DF0004608A4004708A5006730B000B1018A0179
:101E0000CF204E308A01682064008A150A12861994
:101E10000E2FFA308A0104218A01AF290130A30074
:101E20002C308A0105218A150A12812D8A019C25F0
:101E300064000B304E028A150A120318222F8A11F1
:101E40000A16672864004E080D3C8A150A12031D05
:101E50002B2F8A01AF294B104A18CB144A1CCB10E8
:101E6000CA184B15CA1C4B114A19CB154A1DCB1168
:101E7000FE308A01682001308A01682044308A01DE
:101E8000682061308A01682074308A0168206130DE
:101E90008A01682020308A01682074308A01682015
:101EA0006F308A01682020308A01682070308A01F2
:101EB00068206F308A01682072308A01682074308F
:101EC0008A01682073308A0168203A308A016820CC
:101ED00020308A01682020308A016820FE308A0183
:101EE0006820C0308A01682064308A01682061302F
:101EF0008A01682074308A01682061308A01682074
:101F00003D308A0168200230A9005608A400A501CE
:101F10006730B000B1018A01BC2020308A016820FE
:101F20000830A9005608A400A5016730B000B1012F
:101F30008A01AC2064008A150A120618AE2FFA3006
:101F40008A010421D00A64005008103C8A150A1244
:101F5000031DAB2FD0018A150A12F62764008A15DB
:101F60000A128618C22FFA308A010421CF0A6400AF
:101F70004F08103C8A150A12031DBF2FCF018A1586
:101F80000A12F62764008A150A128619CC2FFA3035
:101F90008A0104218A01AF2964008A150A120619F0
:101FA000F32FFA308A0104211030A600A70150084F
:101FB000A200A3018A016C21BC002508BD003C08D9
:101FC0004F07D6000730B6001030B4000730B70016
:101FD0000830B5004B088A011D2056088A011B20D5
:101FE0008A150A122B2F8A150A129A2F1030A60072
:101FF000A7015008A200A3018A016C21BC0025089A
:10200000BD003C084F07D600FE308A016820C03072
:102010008A01682064308A01682061308A01682062
:1020200074308A01682061308A0168203D308A015D
:1020300068200230A9005608A400A5016730B0004E
:10204000B1018A01BC2020308A0168200830A90033
:102050005608A400A5016730B000B1018A01AC2088
:10206000FE308A01682010308A016820FE308A0123
:10207000682010308A016820FE308A016820103004
:102080008A016820FE308A01682010308A016820A9
:10209000FE308A01682010308A016820FE308A01F3
:1020A000682010308A016820FE308A0168201030D4
:1020B0008A016820FE308A01682010308A01682079
:1020C000FE308A01682010308A0168200800143030
:1020D0008A0104214B14FE308A01682001308A01F4
:1020E000682061308A01682064308A016820643089
:1020F0008A01682072308A0168203D308A01682098
:102100000430A9003808A4003908A5006730B000E1
:10211000B1018A01BC2020308A0168200530A90065
:102120003808A4003908A5006730B000B1018A0161
:10213000CF20640003304E028A110A160318B1281A
:102140000730B6001030B4000730B7000830B500D3
:102150004B088A011D2038088A011D208A010220AF
:10216000D6004E08033C031DFF30FF3ABC004E086A
:10217000043C031DFF30FF3ABE003C0884003E08CB
:102180008A014C21BE00BF004E08053C031DFF30F4
:10219000FF3AC0003E083F04840040088A014C21F9
:1021A000C000C1006400400841048A110A160319E6
:1021B000F6283918CB14391CCB10B9184B15B91C9B
:1021C0004B113919CB15391DCB110730B600103022
:1021D000B4000730B7000830B5004B088A011D2055
:1021E00038088A011D208A010220D6004E08A0006E
:1021F00005308A012621BC004E08A0000B308A0160
:102200002E21BE003C0884003E088A014521BE0004
:10221000BF0064003E083F048A110A1603192429EE
:102220000730B6001030B4000730B7000830B500F2
:102230004B088A011D2039088A011D2038088A01AF
:102240001D208A010220D600FE308A016820C0309D
:102250008A01682064308A01682061308A01682020
:1022600074308A01682061308A0168203D308A011B
:1022700068200230A9005608A400A5016730B0000C
:10228000B1018A01BC2020308A0168200330A900F6
:102290005608A400A5016730B000B1018A01CF2023
:1022A000FE308A01682010308A016820FE308A01E1
:1022B000682010308A016820FE308A0168201030C2
:1022C0008A016820FE308A01682010308A01682067
:1022D0005608A000A1011030A200A3018A015021DC
:1022E000D0005008A600A7011030A200A3018A0167
:1022F0006C21BC002508BD003C085602CF006400DC
:102300008A110A1606189329FA308A010421D00A84
:1023100064005008103C8A110A16031D9029D00150
:102320008A110A16702264008A110A168618A729D3
:10233000FA308A010421CF0A64004F08103C8A1148
:102340000A16031DA429CF018A110A1670226400FF
:102350008A110A160619612A4B10FA308A010421E3
:102360001030A600A7015008A200A3018A016C2129
:10237000BC002508BD003C084F07D60064000330B0
:102380004E028A110A160318D6290730B6001030FB
:10239000B4000730B7000830B5004B088A011D2093
:1023A00038088A011D2056088A011B204E08033C6C
:1023B000031DFF30FF3ABC004E08043C031DFF30F4
:1023C000FF3ABE003C0884003E088A014C21BE0052
:1023D000BF004E08053C031DFF30FF3AC0003E0819
:1023E0003F04840040088A014C21C000C100640001
:1023F000400841048A110A1603191B2A3918CB1404
:10240000391CCB10B9184B15B91C4B113919CB1508
:10241000391DCB110730B6001030B4000730B700BB
:102420000830B5004B088A011D2038088A011D209C
:1024300056088A011B204E08A00005308A0126217B
:10244000BC004E08A0000B308A012E21BE003C08C3
:1024500084003E088A014521BE00BF0064003E089A
:102460003F048A110A160319492A0730B6001030B2
:10247000B4000730B7000830B5004B088A011D20B2
:1024800039088A011D2038088A011D2056088A0152
:102490001B20B80A0319B90A3808A0003908A1009E
:1024A0003B08A3003A088A0133218A110A16031D4A
:1024B0005B2AB801B90114308A0104218A110A1675
:1024C000672864008A110A1686196D2A0130A30054
:1024D0005E308A0105218A01AF298A110A167F29F7
:1024E0001030A600A7015008A200A3018A016C21A8
:1024F000BC002508BD003C084F07D600FE308A010D
:102500006820C0308A01682064308A016820613008
:102510008A01682074308A01682061308A0168204D
:102520003D308A0168200230A9005608A400A501A8
:102530006730B000B1018A01BC2020308A016820D8
:102540000330A9005608A400A5016730B000B1010E
:102550008A01CF20FE308A01682010308A0168206D
:10256000FE308A01682010308A016820FE308A011E
:10257000682010308A016820FE308A0168201030FF
:102580008A016820080064000B304E028A110A1686
:10259000031CCC2A8A01AF294B10FE308A01682027
:1025A00001308A01682045308A01682072308A0132
:1025B000682061308A01682073308A0168206930A0
:1025C0008A0168206E308A01682067308A0168209D
:1025D00020308A0168206D308A01682065308A01C8
:1025E00068206D308A0168206F308A01682072305F
:1025F0008A01682079308A01682020308A016820A9
:1026000020308A016820FE308A016820C0308A01AB
:10261000682043308A0168206F308A0168206E305C
:102620008A01682066308A01682069308A01682042
:1026300072308A0168206D308A01682020308A015A
:1026400068203F308A01682020308A0168204230AB
:102650008A01682075308A01682074308A016820F8
:1026600031308A01682020308A01682020308A01B8
:10267000682064008A110A160618442BFA308A0171
:1026800004218A110A16512B64008A110A16861831
:102690004E2BFA308A0104218A01AF298A110A16C9
:1026A000392BFE308A01682001308A0168204530CC
:1026B0008A01682072308A01682061308A016820AE
:1026C00073308A01682069308A0168206E308A017F
:1026D000682067308A01682020308A0168206D30C8
:1026E0008A01682065308A0168206D308A0168207F
:1026F0006F308A01682072308A01682079308A013F
:10270000682020308A01682020308A016820FE304D
:102710008A016820C0308A01682057308A01682009
:1027200061308A01682069308A01682074308A012A
:10273000682020308A01682020308A0168202030FB
:102740008A01682020308A01682020308A016820B0
:1027500020308A01682020308A01682020308A01D8
:10276000682020308A01682020308A0168202030CB
:102770008A01682020308A016820C401C50144080C
:10278000A0004508A1003B08A3003A088A012821BF
:102790008A110A16031D632CFF30D6006400033033
:1027A0004E028A110A160318E62B0730B6001030C5
:1027B000B4000730B7000830B5004B088A011D206F
:1027C00044088A011D2056088A011B204E08033C3C
:1027D000031DFF30FF3ABC004E08043C031DFF30D0
:1027E000FF3ABE003C0884003E088A014C21BE002E
:1027F000BF004E08053C031DFF30FF3AC0003E08F5
:102800003F04840040088A014C21C000C1006400DC
:10281000400841048A110A1603192B2C4518CB14C1
:10282000451CCB10C5184B15C51C4B114519CB15B4
:10283000451DCB110730B6001030B4000730B7008B
:102840000830B5004B088A011D2044088A011D206C
:1028500056088A011B204E08A00005308A01262157
:10286000BC004E08A0000B308A012E21BE003C089F
:1028700084003E088A014521BE00BF0064003E0876
:102880003F048A110A160319592C0730B60010307C
:10289000B4000730B7000830B5004B088A011D208E
:1028A00045088A011D2044088A011D2056088A0116
:1028B0001B2014308A010421C40A0319C50A8A1195
:1028C0000A16031DBF2BFE308A01682001308A01E1
:1028D00068204D308A01682065308A0168206D309B
:1028E0008A0168206F308A01682072308A0168206E
:1028F00079308A01682020308A01682065308A0199
:10290000682072308A01682061308A016820733043
:102910008A01682065308A01682064308A01682055
:1029200020308A01682020308A01682020308A0106
:102930006820FE308A016820C0308A01682050304B
:102940008A01682072308A01682065308A01682017
:1029500073308A01682073308A01682020308A0130
:10296000682042308A01682075308A0168207430FE
:102970008A01682074308A0168206F308A016820DB
:102980006E308A01682020308A01682034308A0144
:10299000682020308A01682020308A016820640085
:1029A0008A110A168619DB2C0130A30090308A01A7
:1029B00005218A01AF298A110A16CF2C63008A11DA
:0429C0000A16DE2CE9
:02400E00313F40
:00000001FF


segunda-feira, 14 de dezembro de 2015

Decodificador alfanumérico com PIC

Extensão do Decodificador BCD para display de 7 segmentos


Utilizei o mesmo PIC 16F676 para um decodificador para apresentar caracteres alfanuméricos em displays de led de 7 segmentos. Para tanto é necessário o uso de mais uma porta para entrar o código binário (agora não mais BCD) de 5 bits, o que permite 32 combinações. Dada a limitação dos displays de 7 segmentos, nem todos caracteres alfanuméricos são possíveis de ser reproduzidos, tais como o "k", "m", "w", "z", "x", e o "q" pra não confundir com o "9".



Segue a tabela com os códigos de entrada na PORT A:
PORT A  
4 3 2 1 0  Caractere
0 0 0 0 0   0
0 0 0 0 1   1
0 0 0 1 0   2
0 0 0 1 1   3
0 0 1 0 0   4
0 0 1 0 1   5
0 0 1 1 0   6
0 0 1 1 1   7
0 1 0 0 0   8
0 1 0 0 1   9
0 1 0 1 0   A
0 1 0 1 1   b
0 1 1 0 0   C 
0 1 1 0 1   d
0 1 1 1 0   E
0 1 1 1 1   F
1 0 0 0 0   g
1 0 0 0 1   H
1 0 0 1 0   i
1 0 0 1 1   J
1 0 1 0 0   L
1 0 1 0 1   n
1 0 1 1 0   o
1 0 1 1 1   P
1 1 0 0 0   r
1 1 0 0 1   t
1 1 0 1 0   u
1 1 0 1 1   y
1 1 1 0 0   -
1 1 1 0 1   =
1 1 1 1 0   [
1 1 1 1 1   ]

Com a utilização de mais um bit de entrada, a seleção de saídas para catodo comum ou anodo comum deixa de existir e o decodificador só funciona para catodo comum.

Os códigos Hexa estão a seguir:
:100000002E288001840AFF3E031D01282928A30110
:10001000A200FF30A207031CA307031C29280330FA
:10002000A100DF3015200928A101E83EA000A109A8
:10003000FC30031C1E28A00703181B28A00764001F
:10004000A10F1B2820182428A01C282800002828DD
:10005000080083130313831264000800073099001B
:1000600083161F30850087019101203084004030C5
:1000700083120120BC01640020303C02031849288F
:100080003C08B80058200130A300F4300820BC0F11
:100090003B280830B8001F300505B8006400380858
:1000A0003902031D54284B283808B90058204B2822
:1000B00038081F3C031C86285F20870086280030F4
:1000C0008A003808663E03188A0A82001F34033407
:1000D0002D342734333436343E3403343F34333410
:1000E0003B343E341C342F343C34383437343B34C6
:1000F00002340F341C342A342E34393428343C343E
:100100000E343734203424341C34073438081F3C70
:10011000031CB8289120013903198512031D851687
:10012000B82800308A003808983E03188A0A8200EE
:100130000134003401340134003401340134013419
:100140000134013401340034013400340134013409
:1001500001340034003400340034003400340134FD
:1001600000340034003400340034003401340134ED
:0601700008006300B9283D
:02400E00C43FAD
:00000001FF

E um pequeno vídeo de demonstração dos caracteres gerados: