Relógio Binário com PIC
Em 2004 eu bolei esse relógio binário usando um PIC 16F628 já que começaram a aparecer alguns projetos semelhantes e eu quis ter o meu. A ideia era usar leds pra representar os bits que representam números binários pra apresentar a hora e dia da semana. Passado esse tempo todo eu resolvi publicar aqui no blog pra deixar documentado e deixar mais um projetinho bacana usando PIC.
Eu usei uma placa de acrílico transparente para servir de suporte como se fosse um painel. Tive que dobrar um pedaço usando uma pequena tocha de algodão e álcool pra amolecer a dobra e fazer a base. No fim uns furos nos cantos pra prender com os espaçadores de tubo de alumínio e parafuso. O resultado final foi esse:
Ao todo são 23 leds dispostos em uma matriz de 7 linhas por 4 colunas com acendimento multiplexado.
A leitura do relógio segue essa lógica:
Aqui um detalhe do relógio e a parte traseira:
A precisão é obtida a partir do cristal de 4MHz do oscilador principal do PIC. Muitos relógios e RTCs usam um cristal de 32768Hz no oscilador auxiliar do PIC. Eu optei por pegar a base de tempo a partir do próprio oscilador principal. Pra isso uma rotina em assembly usa o Timer1 do PIC pra gerar um estouro e uma interrupção a cada meio segundo e incrementar a variável de segundo (na verdade de meio segundo = halfsec). O resultado é que o relógio tem uma excelente precisão e depende apenas do cristal.
MOVWF wsave
SWAPF STATUS,W
CLRF STATUS
MOVWF ssave
MOVF PCLATH,W
MOVWF psave
MOVLW 221
MOVWF TMR1L
MOVLW 11
MOVWF TMR1H 'carrega valor 11x256+221=3037 no contador TMR1, falta 62499 contagens x8us=0,5s
BCF PIR1,0
INC halfsec 'o contador TMR1 estoura a cada 0,5s e incrementa a variavel
BTFSS halfsec,1
GOTO xxx
CLRF halfsec
INC unseg
xxx MOVF psave,W
MOVWF PCLATH
SWAPF ssave,W
MOVWF STATUS
SWAPF wsave,F
SWAPF wsave,W
BSF interr,0
RETFIE
Aqui o código hexadecimal para gravar no PIC:
:02000000B42822
:10000800CA28A400400884003E082620841300055E
:100018002C1C3E06031923282408031D1B282A0824
:10002800FF3E031C24280A3030202A082428240AEA
:10003800FF3003192328240B23282B082428AD0973
:10004800AD0CAF2884178004AF2883178001840A79
:10005800FF3E031D2A28AF28A301A200FF30A207F4
:10006800031CA307031CAF280330A100DF303E2088
:100078003228A101E83EA000A109FC30031C472852
:10008800A00703184428A0076400A10F44282018DB
:100098004D28A01C5128000051280800013EA70047
:1000A8000A30A200A3017D20A70B572824080800C6
:1000B800A101A301A20002306628A101A301A200A8
:1000C80001306628A80023082102031D6D28220894
:1000D8002002043003180130031902302805031DDB
:1000E800FF30AF280038031DFF300405031DFF3023
:1000F800AF28A501A4011030A600210DA40DA50D5F
:100108002208A4022308031C230FA502031893281E
:100118002208A40723080318230FA5070310A00D1E
:10012800A10DA60B81282008AF281030A800A10136
:10013800A001A70CA60C031CA7282208A0072308C7
:100148000318230FA107A10CA00CA50CA40CA80B45
:100158009D282408AF288313031383126400080022
:1001680007309F008316F830850086012030840010
:10017800603083122A20A030840050302A2020309A
:100188008400303029200130C300E228D400030E57
:100198008301CE000A08CD00DD308E000B308F00C1
:1001A8000C10C90AC91CDA28C901D30A4D088A00EB
:1001B8004E0E8300D40E540E4C1409000330A300D5
:1001C800E8303120C0308B003530900083160C1495
:1001D8006400831253080A3C031DF428D3013F210D
:1001E80064008519F9288B13B8296400051AFD28BD
:1001F800802A7C214408A00045085C20B2004F08F2
:10020800A00050085C20B40032088400340876202E
:10021800B400B5004608A00047085C20B6003408C2
:100228003504840036087620B600B7005108A000CF
:1002380052085C20B8003608370484003808762055
:10024800B800B9004208A00001305C20BA003808A4
:10025800390484003A087620BA00BB0064003A08E2
:100268003B040319392905153A2905116400851A33
:100278003E29C201E628C80A64004808063C031D56
:100288004729C80148210800D10A640051080A3CDE
:10029800031D5029D10151210800C60A64004608EF
:1002A800063C031D5929C6015A210800CA0A05152A
:1002B800C8303020051164004A08183C031D66291F
:1002C800CA0173214A08A000A10100305220CF00C2
:1002D8004A08A000A10101305220C4000800C30A46
:1002E80064004308083C031D7B290130C300080053
:1002F800D5016400C93055020318B72964004C08B9
:10030800013C031D8929CC01E62853088600851481
:10031800023030208510480886000514023030204D
:100328000510510886000000861702303020861319
:100338000000460886000000061702303020061329
:1003480000004F0886000000861602303020861212
:10035800000044088600000006160230302006120D
:100368000000D50F7D2908004408860001303020A0
:100378000616C83030206400851AD629C40A6400DD
:100388004408033C031DD629C4010A30A600A7016E
:100398004408A200A3019920B2002508B3004F0821
:1003A8003207CA006400051ADB290612EB2905305A
:1003B800C0000830BE00AC016430AA00AB010130B7
:1003C800AD0056080520D6000318E228B8294F08C2
:1003D8008600013030208616C83030206400851A27
:1003E800122ACF0A64004F080A3C031DFC29CF01DA
:1003F8004F08A00003306120B2004408A00002307A
:100408005C20B4003208840034087620B400B500BB
:100418006400340835040319122ACF010A30A600F3
:10042800A7014408A200A3019920B2002508B3003F
:100438004F083207CA006400051A242A8612342A93
:100448000530C0000830BE00AC016430AA00AB0122
:100458000130AD0056080520D6000318E228EB2924
:1004680046088600013030200617C8303020640066
:10047800851A452AC60A64004608063C031D452A13
:10048800C6016400051A4A2A06135A2A0530C00014
:100498000830BE00AC016430AA00AB010130AD00E9
:1004A80056080520D6000318E228342A5108860089
:1004B800013030208617C83030206400851A6B2A36
:1004C800D10A640051080A3C031D6B2AD10164005B
:1004D800051A702A0613B8290530C0000830BE0076
:1004E800AC016430AA00AB010130AD00560805200C
:1004F800D6000318E2285A2A0130A300F43031202C
:100508000130C20045088600013030200616C83088
:1005180030206400851AA42AC50A64004508033CF3
:10052800031DA42AC5010A30A600A7014508A20098
:10053800A3019920B2002508B30050083207CB0068
:100548006400051AA92A0612B92A0530C000083025
:10055800BE00AC016430AA00AB010130AD00560802
:100568000520D6000318E228802A500886000130AA
:1005780030208616C83030206400851AE02AD00A58
:10058800640050080A3C031DCA2AD0015008A00084
:1005980003306120B2004508A00002305C20B4009E
:1005A8003208840034087620B400B50064003408AA
:1005B80035040319E02AD0010A30A600A70145082E
:1005C800A200A3019920B2002508B3005008320701
:1005D800CB006400051AF22A8612022B0530C000EF
:1005E8000830BE00AC016430AA00AB010130AD0098
:1005F80056080520D6000318E228B92A47088600BD
:10060800013030200617C83030206400851A132BBB
:10061800C70A64004708063C031D132BC701640082
:10062800051A182B0613282B0530C0000830BE0009
:10063800AC016430AA00AB010130AD0056080520BA
:10064800D6000318E228342A5208860001303020E8
:100658008617C83030206400851A392BD20A640006
:1006680052080A3C031D392BD2016400051A3E2B9F
:100678000613802A0530C0000830BE00AC01643083
:10068800AA00AB010130AD0056080520D6000318BA
:08069800E228282B63004E2B21
:02400E00053F6C
:00000001FF
E o esquema elétrico do relógio:
E um filminho mostrando o relógio contando o tempo: