Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Need help to explain the meaning of the code

Status
Not open for further replies.

cjhaw

New Member
Hi,
Can anyone explain the meaning of the code from the 2 example I posted below?
_________________________________________________________________

example 1:

/running light

#include <16f876A.h>
#use delay(clock = 20000000)
#fuses hs, noprotect, nowdt, nolvp

#byte PORTB=6
#byte PORTC=7

main()
{
set_tris_b(0);
set_tris_c(0);
do{
portb=0b11111111;
portc=0b11111111;
delay_ms(2000);
portb=0b01010101;
portc=0b01010101;
delay_ms(2000);
portb=0b10101010;
portc=0b10101010;
delay_ms(2000);
}while(1);
}

example 2:

//lcd message display

#include <16f876A.h>
#use delay(clock = 20000000)
#fuses hs, noprotect, nowdt, nolvp
#define use_portb_lcd TRUE
#include<lcd.c>

#byte PORTB=6
#byte PORTC=7

main()
{
set_tris_b(0);
set_tris_c(0);
lcd_init();
do{
lcd_putc("\fWelcome to\n");
delay_ms(1000);
lcd_putc("**UNITEN**");
delay_ms(1000);
portb=0b10101010;
lcd_putc("\f*Nice Day!!*\n");
lcd_putc("BY: BIZCHIP");
delay_ms(2000);
}while(1);
}

_________________________________________________________________
From the examples, can someone explain the meaning of 'fuses hs, noprotect, nowdt, nolvp', 'byte PORTB=6', 'byte PORTC=7', 'set_tris_b(0)', the code '0b11111111' and the following code?

Thank you.
 
how about you learn the basics and then you'll immediately know what they do.

hi,
o..emm..what 'basic' do you meant? actually i already learnt come of the c++ code..but not for the pic code..i am actually not in electronic background..now i am confusing with the code such as 0b11111111 and so on that i wrote above..from where i can get those 'basic'?thx..
 
Last edited:
basics as in how to turn a LED on or off, how to set values in either binary, hex or decimal, what configuration bits are, and names of the common registers
 
o..ya..the 11111111 is binary code..in hex is FF, in dec is 255, and in oct is 377..
but what is the physical meaning of those figure?
 
o..ya..the 11111111 is binary code..in hex is FF, in dec is 255, and in oct is 377..
but what is the physical meaning of those figure?
 
they are numbers... like
Code:
char foo = 'a';
char bar = 'c'

// or

int foo = 20;
int bar = 5;

'a' is also equal to 61 or 0x3D or 111101

'c' is also equal to 63 or 0x3F or 111111

20 is equal to 0x14 or 10100

and 5 is equal to 0x05 or 101
 
Last edited:
Three interesting lines.
Code:
set_tris_b(0);
   	portb=0b11111111;
   	portb=0b01010101;

TRISB is the portb data direction register.
set_tris_b(0);
Is the same as saying
TRISB=0b00000000;
in many other compilers. Each bit that is 0 in TRISB will configure the coresponding bit position int the PORTB register as an output. Setting TRIS bits to 1 will configure PORT bits for input (or TRIState).


PORTB is a location connect to the port B pins on the PIC. On the line
#byte PORTB=6
we have told the compiler that is location six in the processor map.

The line
portb=0b11111111; // I would rather see this as PORTB=0b11111111
will set all portb output pins to a logical 1.

I explain all this in detail for the P18 which is very similar to the PIC16 at the C level in this tutorial.

https://www.electro-tech-online.com/custompdfs/2009/11/JunebugTut1C3-1.pdf
on this page
3v0's Tutorials

3v0
 
How about reading the data sheet?! The information about the various special purpose registers is found there.
 
hi all,
sorry for not reply for so long as i was busy with something..
i had solved the problem due to ur explanation and further studies on it.

Thank you for help..
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top