Figure 1. |
I have previously made an error in this blog which I will correct from here forward. This error is more of a "good practices" error in code writing. In figure 1 above we see a code example from a previous lesson. Within the main program we set the data direction using TRISIO=0x8; where 0x8 is considered a "literal" using hexadecimal. This is bad practice. Later on when code gets longer, and things begin to get more cluttered and harder to find, you will always find it helpful that you have written code in such a way that going back and making revisions is easier.
Bitmapped registers, or registers that contain multiple bit-oriented values such as the TRISIO, GPIO, and OPTION registers, should always be expressed in binary rather than a literal. Doing this makes the code easier to read and understand since we know off-hand that in binary a "0" is false and a "1" is true. There is no need to convert from hex code into binary while scanning through and/or writing our program.
Making the correction to our program, we will change the line TRISIO=0x8; to TRISIO=0b00001000; (Figure 2.) A string of binary is preceded by a zero and a lowercase b.
Figure 2. |
November 24, 2014: Edited this post by removing a section on Shadow Registers. This topic is covered in better detail later and was removed from here to avoid confusion and for simplicity of lesson flow.
Hola muy interesante la pagina felicitaciones.
ReplyDeleteTengo una consulta, tengo que hacer un proyecto usando el PIC12F629 con el compilador XC8 y se trata de lo siguiente: por un puerto del pic coloco un pulsador y por otros 2 puertos distintos 2 leds, cuendo presiono y suelto el boton se enciende el primer led durante 1 segundo y luego de 20 segundos aproccimadamente se enciende el segundo led durante 1 segundo luego de eso quedan los led apagados a la espera de que se presione nuevamente el pulsador y comiensa nuevamente el ciclo.
Si puede ayudarme a realizar este proyecto te estare muy agradecido.
Desde ya mucgas gracias y a tus ordenes.
Saludos
Marcos Romero
Hello very interesting congratulations page .
ReplyDeleteI have a question , I have to do a project using PIC12F629 with the compiler XC8 and is as follows: for a port pic and put a button for another 2 different ports 2 leds , cuendo pressed and loose the button is lit on led for 1 second and then 20 seconds aproccimadamente the second led lights for 1 second after that the leds are off waiting for you again press the button and comiensa the cycle again.
If you can help me with this project i will be very grateful.
From already thank mucgas with your orders .
Regards
Marcos Romero
Marcos,
DeleteSeems there is an obvious language barrier between us. I think what you're saying is you need your program to have 2 LEDs and 1 button. The program sits and waits for you to press a button, and when the button gets pressed, LED 1 goes on for 1 second and turns off, then LED 2 goes on for 20 seconds, at which point LED 1 turns back on for another 1 second? My apologies if I misunderstand. You can always seek expert advice at forum.allaboutcircuits.com, where I am a member.