![]() ![]() Once the supply is turned ON, then the quartz oscillator will be activated through the control logic register. Thus each instruction will be executed within the microcontroller at a quick speed. On the next part of this tutorial, we will look at a new way to code PICs.The microcontroller chip is a high-speed device, but as compared with a computer it is slow. Conversely, PORTA.0 LED turns off and PORTA.1 LED lights up when switch is turned off. When the switch is turned on, PORTA.0 LED lights up while PORTA.1 LED turns off. Modify the code above so that another LED is attached to PORTA.1. TRISA = 0x01 // Initialize All PORTA as output TRISB = 0x01 // Initialize PORTB0 as all input The above ASM code can be implemented in XC8 like this: #define _XTAL_FREQ 4000000 A delay is introduced for stability and the program checks the status of PORTB.0 again. Otherwise, the program will jump to the on label and sets PORTA.0. If that pin is set (switch off), line 20 is skipped and the program will do an endless loop. The main routine checks if PORTB.0 is set or cleared using the BTFSS op-code. After that, we shift back to bank 0 (line 16). Then we write the corresponding literals to the TRIS registers. This is done by setting bit RP0 on the STATUS register. On the start routine, we begin with shifting to bank 1 since the TRIS registers are found there. MAIN_PROG CODE let linker place main program RES_VECT CODE 0x0000 processor reset vector TODO INSERT CONFIG CODE HERE USING CONFIG BITS GENERATOR The circuit for this code should look like this: The LED should turn on when the switch is on, and turn off when the switch is off. A LED is connected to PORTA,0 while a switch is attached to PORTB,0. But I know that PORTA.4 has a secondary function of reading clock pulses. As to why is that, I am not entirely sure. You can do the same for the 4 pins on PORTA with the exception of PORTA.4, which can only sink current and not source it. All PORTB pins can be set as either input or output. The PIC16F84A has 5 PORTA pins and 8 PORTB pins. I suggest you go read assembly language for PICs if you need a refresher. Of course, the examples above are some of the few ways to set and clear bits on a register using PIC ASM. So if you want to set PORTA.0 as an output then do this: BCF TRISA, 0 For example, if we want to set all PORTB’s as input then the ASM code below does the job: MOVLW b’11111111’Ĭlearing the pin does the opposite. To set a pin as input, we set its corresponding TRIS bit. Generally, we don’t use floating pins with PICs. A floating pin is a pin which has not been defined as either input or output. If you need to use a button, you set the button pin as input. If you want to connect an LED to a pin, you need to set that pin as an output. In this article, we will look at how to manipulate the pins of the PIC16F84A microcontroller using the TRIS register.Ī microcontroller’s pins can have three state: input, output or floating. ![]() PICs call them TRIS registers which is supposed to be short for “TRIState”. AVR microcontrollers call them Data Direction Registers (DDR) while ARM-based STM32 has a group of “GPIO” registers. For most microcontrollers, the input and output channels are handled by data direction special function registers.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |