View previous topic :: View next topic |
Author |
Message |
msa
Joined: 07 Apr 2010 Posts: 15
|
#byte and #bit |
Posted: Sat Apr 10, 2010 10:07 am |
|
|
Dear all
I have 18f2550. I need to use #byte and #bit to name my pins.
My code :
Code: |
#include <18F2550.h>
#use delay(clock=8000000)
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16)
#FUSES NOMCLR //Master Clear pin disabled
#byte PORTA=0xF80
#bit led1=PORTA.0
#bit led2=PRATA.1
#bit led3=PORTA.2
void main(void){
setup_oscillator(OSC_8MHZ);
for(;;){
output_high(led1);
output_high(led2);
output_high(led3);
delay_ms(1000);
output_low(led1);
output_low(led2);
output_low(led3);
}
}
|
but this code not working.
thanks |
|
|
taner_73
Joined: 29 Jan 2008 Posts: 1
|
|
Posted: Sat Apr 10, 2010 10:45 am |
|
|
Hello,
first this is wrong:
and should be:
and second this code block:
Code: | output_high(led1);
output_high(led2);
output_high(led3); |
should be:
Code: | led1=1;
led2=1;
led3=1; |
and this:
Code: | output_low(led1);
output_low(led2);
output_low(led3); |
should be:
Code: |
led1=0;
led2=0;
led3=0;
|
Best regards,
Taner
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
Ttelmah |
Posted: Sat Apr 10, 2010 12:53 pm |
|
|
Add, third, if you are talking directly to the pins, then _you_ have to control the TRIS.
Best Wishes |
|
|
msa
Joined: 07 Apr 2010 Posts: 15
|
|
Posted: Sat Apr 10, 2010 12:56 pm |
|
|
Hi taner_73
Hi Ttelmah
Thanks for your answers.
It is now working.
My code after update:
Code: |
#include <18F2550.h>
#use delay(clock=8000000)
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or
#FUSES NOMCLR //Master Clear pin disabled
#byte PORTA=0xF80
#bit led1=PORTA.0 // bit 0
#bit led2=PORTA.1 // bit 1
#bit led3=PORTA.2 // bit 2
void main(void){
setup_oscillator(OSC_8MHZ);
SET_TRIS_A(0xF8); // 1111 1000
output_a(0);
for(;;){
led1=1;delay_ms(500);led1=0;
led2=1;delay_ms(500);led2=0;
led3=1;delay_ms(500);led3=0;
}
} |
Last edited by msa on Wed Apr 14, 2010 1:51 am; edited 1 time in total |
|
|
thiam
Joined: 06 Apr 2010 Posts: 13
|
|
Posted: Sat Apr 10, 2010 8:59 pm |
|
|
What is difference between #bit and #byte ? |
|
|
|