#define TRISB = 0b00000000
#define ADCON0 = 0b00000000 'ADON off
#define ADCON1 = 0b00000110 'all digital
#define CMCON = 0b00000111
#INCLUDE <16F876A.h> //INCLUSÃO DA BIBLIOTECA liblary
#FUSES NOWDT //Watch Dog Timer desabilitado
#FUSES HS //oscilador cristal <= 4mhz
#FUSES PUT //Power Up Timer
#FUSES NOPROTECT //sem proteção para leitura da eprom
#FUSES BROWNOUT //Resetar quando detectar brownout
//#FUSES MCLR //Reset habilitado
#FUSES NOLVP // prog. baixa voltagem desabilitado
#FUSES NOCPD //
#use delay(clock=20000000)
#use fast_io(a)
#use fast_io(b)
#define TRISA 0b00000000 // 0 output, 1 input
#define TRISB 0b00000000 // ou #define trisb 0x00
#define ADCON0 = 0b00000000 // 'ADON off
#define ADCON1 = 0b00000110 // 'all digital
#define CMCON = 0b00000111
void main()
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
// TODO: USER CODE!!
while(true)
{
output_low(PIN_B0);
output_high(PIN_B1);
output_low(PIN_B2);
delay_ms( 1000 );
output_low(PIN_B0);
output_low(PIN_B1);
output_high(PIN_B2);
delay_ms( 1000 );
output_high(PIN_B0);
output_low(PIN_B1);
output_low(PIN_B2);
delay_ms( 1000 );
};
}
#include <16F876A.h>
Do you have to use SET_TRIS_x()? I tried to install the CCS demo, but it is not working for me. I found the SET_TRIS_x() in the 16F876A header file comments. If you use #define TRISA, etc does the CCS compiler know what to do with it or do you have to use it somewhere in your code?
/* TEST LED Program for Riclamer
Processor: 16F876A at 20 Mhz
power a led 3 colors (4 pin) in RB0, RB1, RB2.
---------
!MCLR/Vpp |1 28| RB7/PGD
RA0/AN0 |2 27| RB6/PGC
RA1/AN1 |3 26| RB5
RA2/AN2/VREF- |4 25| RB4
RA3/AN3/VREF+ |5 24| RB3/PGM
RA4/T0CKI |6 23| RB2 -----> 220 Ohm --> B LED -|
RA5/AN4/!SS |7 22| RB1 -----> 220 Ohm --> G LED -+-GND
Vss |8 21| RB0/INT -----> 220 Ohm --> R LED -|
OSC1/CLKIN |9 20| Vdd
OSC2/CLKOUT |10 19| Vss
RC0/T1OSO/T1CKI |11 18| RC7/RX/DT
RC1/T1OSI/CCP2 |12 17| RC6/TX/CK
RC2/CCP1 |13 16| RC5/SDO
RC3/SCK/SCL |14 15| RC4/SDI/SDA
---------
My circuit is energized with a 9V batery and reguled to 5v with LM78L05. (pin 8 ) (pin 1 MCLR)
I have a external crystal 20MHz with capacitor ceramic 33pf (pin 9, 10 ).
*/
;Set up the assembler options (Chip type, clock source, other bits and pieces)
LIST p=16F876A, r=DEC
#include <P16F876A.inc>
__CONFIG _HS_OSC & _WDT_OFF & _LVP_OFF
;********************************************************************************
;Vectors
ORG 0
goto BASPROGRAMSTART
ORG 4
retfie
;********************************************************************************
;Start of program memory page 0
ORG 5
BASPROGRAMSTART
;Call initialisation routines
call INITSYS
;Automatic pin direction setting
banksel TRISB
bcf TRISB,0
;Start of the main program
MAIN
banksel PORTB
bsf PORTB,0
goto MAIN
BASPROGRAMEND
sleep
goto BASPROGRAMEND
;********************************************************************************
INITSYS
bcf ADCON0,ADON
banksel ADCON1
bcf ADCON1,ADFM
bcf ADCON1,PCFG3
bsf ADCON1,PCFG2
bsf ADCON1,PCFG1
bcf ADCON1,PCFG0
movlw 7
movwf CMCON
banksel PORTA
clrf PORTA
I changed the Crystal and cap 0.01uf. I tested with multimeter, and under MCLR (pin1) are with 6,75v.
Look at second code, the include 16f876a.h is arready done.
I built the code, but not run...
Can you send me simple code in ASM ( MPLAB assemby ) to test output_high under "RB0" ?? Maybe the problem is the code...
Tanks
Voltage on any pin with respect to VSS (except VDD, MCLR. and RA4) ....................................... -0.3 V to (VDD + 0.3 V)
Voltage on VDD with respect to VSS ........................................................................................................... -0.3 to +7.5 V
Voltage on MCLR with respect to VSS (Note 2) ................................................................................................0 to +14 V
Voltage on RA4 with respect to Vss .................................................................................................................0 to +8.5 V
#byte PORTB = 6 //Just an example, check the
#define ALL_OUT 0 //DATA sheet for the correct
#define ALL_IN 0xff //address for your chip
main() {
int i;
set_tris_b(ALL_OUT);
PORTB = 0;// Set all pins low
for(i=0;i<=127;++i) // Quickly count from 0 to 127
PORTB=i; // on the I/O port pin
set_tris_b(ALL_IN);
i = PORTB; // i now contains the portb value.
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?