Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
// LCD module connections
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections
void main()
{
ANSEL = 0; // Configure AN pins as all digital I/O (safer this way to test)
ANSELH = 0;
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;
TRISB = 0b00000000; // set PORTB all outputs!
Lcd_Init(); // Initialize LCD (this also clears it!)
Lcd_Out(1,1,"Test line 1"); // Write text in first row
Lcd_Out(2,1,"Test line 2"); // Write text in second row
while(1) // Endless loop
{
}
}
Prototype unsigned short Button(unsigned short *port, unsigned short pin, unsigned short time, unsigned short active_state);
Returns Returns 0 or 255.
Description Function eliminates the influence of contact flickering upon pressing a button (debouncing).
Parameter port specifies the location of the button; parameter pin is the pin number on designated port and goes from 0..7; parameter time is a debounce period in milliseconds; parameter active_state can be either 0 or 1, and it determines if the button is active upon logical zero or logical one.
Requires Nothing.
Example Example reads RB0, to which the button is connected; on transition from 1 to 0 (release of button), PORTD is inverted:
do {
if (Button(&PORTB, 0, 1, 1)) oldstate = 1;
if (oldstate && Button(&PORTB, 0, 1, 0)) {
PORTD = ~PORTD;
oldstate = 0;
}
} while(1);
another thing is what is this stand fordo {
if (Button(&PORTA, 1, 1, 1)){
oldstate = 1;
Lcd_Out(1,1,txt1); // Write text in first row
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
}
if (oldstate && Button(&PORTB, 1, 1, 0)) {
Lcd_Out(1,1,txt2); // Write text in first row
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
oldstate = 0;
}
} while(1);
what does it invert?? how if i din put that in??PORTD = ~PORTD; // invert portD
if (oldstate && Button(&PORTB, 0, 1, 0))
// unsigned short Button(unsigned short *port, unsigned short pin, unsigned short time, unsigned short active_state)
// if PORTA.F3 pressed for 20 mS to state 1 (HI), then display text
if (Button(&PORTA, 3, 20, 1))
{
Lcd_Out(1,1,txt1); // Write text in first row
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
}