Mimuwhen
Junior Member level 3
- Joined
- Oct 7, 2014
- Messages
- 29
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 284
// Lcd module connections
sbit LCD_RS at RD0_bit;
sbit LCD_EN at RD1_bit;
sbit LCD_D4 at RD2_bit;
sbit LCD_D5 at RD3_bit;
sbit LCD_D6 at RD4_bit;
sbit LCD_D7 at RD5_bit;
sbit LCD_RS_Direction at TRISD0_bit;
sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD3_bit;
sbit LCD_D6_Direction at TRISD4_bit;
sbit LCD_D7_Direction at TRISD5_bit;
// End Lcd module connections
void main(){
TRISA = 0xFF;
PORTA = 0x00;
TRISB = 0b10000000;
PORTB = 0b00000000;
TRISD = 0X00;
PORTD = 0X00;
Lcd_Init(); // Initialize Lcd
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
if(PORTB.F7=1) // If button is not pushed
{
while(1){ // Repeat sequence
Lcd_Out(1,6,"Message 1");
Delay_ms(500);
Lcd_Out(1,6,"Message 2");
Delay_ms(500);
Lcd_Out(1,6,"Message 3");
Delay_ms(500);
}
}
else{ // If button is pressed
Delay_ms(100); // Debounce
if(PORTB.F7=0){ // If button is still pressed
Lcd_Out(1,2,"Screen Toggled");
}
}
}
I think this should beif(PORTB.F7=1) // If button is not pushed
if(PORTB.F7==1) // If button is not pushed
void main(){
TRISA = 0xFF;
PORTA = 0x00;
TRISB = 0b10000000;
PORTB = 0b00000000;
TRISD = 0X00;
PORTD = 0X00;
Lcd_Init(); // Initialize Lcd
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
while(1){
if(PORTB.F7=1) // If button is not pushed
{
// Repeat sequence
Lcd_Out(1,6,"Message 1");
Delay_ms(500);
Lcd_Out(1,6,"Message 2");
Delay_ms(500);
Lcd_Out(1,6,"Message 3");
Delay_ms(500);
}
else{ // If button is pressed
Delay_ms(100); // Debounce
if(PORTB.F7=0){ // If button is still pressed
Lcd_Out(1,2,"Screen Toggled");
}
}
}
}
void main(){
unsigned int var1=2;
unsigned int var2=3;
unsigned int var3=2;
unsigned int var4=0;
TRISA = 0xFF;
PORTA = 0x00;
TRISB = 0b10000000;
PORTB = 0b00000000;
TRISD = 0X00;
PORTD = 0X00;
Lcd_Init(); // Initialize Lcd
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
while(1){
if(PORTB.F7==1) // If button is not pushed
{ // Repeat sequence
Lcd_Out(1,4,"Total01:");
Lcd_Chr(1,14,var1); // Print value of Var1 on screen
Delay_ms(500);
Lcd_Out(1,4,"Total02:");
Lcd_Chr(1,14,var2); // Print value of Var2 on screen
Delay_ms(500);
Lcd_Out(1,4,"Total03:");
Lcd_Chr(1,14,var3); // Print value of Var3 on screen
Delay_ms(500);
}
else{ // If button is pressed
var4=var1+var2+var3; // Add var1-3 store result in var 4
Lcd_Out(1,3,"Gran Total:");
Lcd_Chr(2,6,var4); // Print value of var4 on screen
Delay_ms(500);
Lcd_Cmd(_LCD_CLEAR);
}
}
}
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 unsigned int var1, var2, var3, var4; char lcdData[17]; while(1) { IntToStr(var1, lcdData); Lcd_Chr(1,14,var1); IntToStr(var2, lcdData); Lcd_Chr(1,14,var2); IntToStr(var3, lcdData); Lcd_Chr(1,14,var3); IntToStr(var4, lcdData); Lcd_Chr(2,6,var4); }
void main(){
unsigned int var1=0;
unsigned int var2=0;
unsigned int var3=0;
unsigned int var4=0;
char lcdData[17];
TRISA = 0xFF;
PORTA = 0x00;
TRISB = 0b10000000;
PORTB = 0b00000000;
TRISD = 0X00;
PORTD = 0X00;
Lcd_Init(); // Initialize Lcd
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
while(1){
if(PORTB.F7==1) // If button is not pushed
{
Lcd_Out(1,4,"Total-1:");
IntToStr(var1, lcdData);
Lcd_Chr(1,14, var1); // Print value of Var1 on screen
Delay_ms(500);
Lcd_Out(1,4,"Total-2:");
IntToStr(var2, lcdData);
Lcd_Chr(1,14,var2); // Print value of Var2 on screen
Delay_ms(500);
Lcd_Out(1,4,"Total-3:");
IntToStr(var3, lcdData);
Lcd_Chr(1,14,var3); // Print value of Var3 on screen
Delay_ms(500);
}
else{ // If button is pressed
var4=var1+var2+var3;
Lcd_Out(1,3,"Gran Total:");
IntToStr(var4, lcdData);
Lcd_Chr(2,6,var4);
Delay_ms(500);
Lcd_Cmd(_LCD_CLEAR);
}
}
}
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 unsigned int var1=0; unsigned int var2=0; unsigned int var3=0; nsigned int var4=0; char lcdData[17]; void main(){ TRISA = 0xFF; PORTA = 0x00; TRISB = 0x80; PORTB = 0x00; TRISD = 0x00; PORTD = 0x00; Lcd_Init(); // Initialize Lcd Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off Lcd_Cmd(_LCD_CLEAR); // Clear display while(1){ if(PORTB.F7==1) // If button is not pushed { Delay_ms(100); if(PORTB.F7==1) // If button is not pushed { Lcd_Out(1,4,"Total-1:"); IntToStr(var1, lcdData); Lcd_Out(1,14, var1); // Print value of Var1 on screen Delay_ms(500); Lcd_Out(1,4,"Total-2:"); IntToStr(var2, lcdData); Lcd_Out(1,14,var2); // Print value of Var2 on screen Delay_ms(500); Lcd_Out(1,4,"Total-3:"); IntToStr(var3, lcdData); Lcd_Out(1,14,var3); // Print value of Var3 on screen Delay_ms(500); } } else{ // If button is pressed var4=var1+var2+var3; Lcd_Out(1,3,"Gran Total:"); IntToStr(var4, lcdData); Lcd_Out(2,6,var4); Delay_ms(500); Lcd_Cmd(_LCD_CLEAR); } } }
void main(){
unsigned int var1=0;
unsigned int var2=0;
unsigned int var3=0;
unsigned int var4=0;
char lcdData[17];
TRISA = 0xFF;
PORTA = 0x00;
TRISB = 0b10000000;
PORTB = 0b00000000;
TRISD = 0X00;
PORTD = 0X00;
Lcd_Init(); // Initialize Lcd
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
while(1){
if(PORTB.F7==1) // If button is not pushed
{
Delay_ms(100);
if(PORTB.F7==1)
{ // Repeat sequence
Lcd_Out(1,4,"Total-1:");
IntToStr(var1, lcdData);
Lcd_Out(1,14, var1);
Delay_ms(500); // Print value of Var1 on screen
Lcd_Out(1,4,"Total-2:");
IntToStr(var2, lcdData);
Lcd_Out(1,14,var2); // Print value of Var2 on screen
Delay_ms(500);
Lcd_Out(1,4,"Total-3:");
IntToStr(var3, lcdData);
Lcd_Out(1,14,var3); // Print value of Var3 on screen
Delay_ms(500);
}
}
else{ // If button is pressed
var4=var1+var2+var3;
Lcd_Out(1,3,"Gran Total:");
IntToStr(var4, lcdData);
Lcd_Out(2,6,var4);
Delay_ms(500);
Lcd_Cmd(_LCD_CLEAR);
}
}
}
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 void main(){ unsigned int var1=0; unsigned int var2=0; unsigned int var3=0; unsigned int var4=0; char lcdData[17]; TRISA = 0xFF; PORTA = 0x00; TRISB = 0b10000000; PORTB = 0b00000000; TRISD = 0X00; PORTD = 0X00; Lcd_Init(); // Initialize Lcd Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off while(1){ if(PORTB.F7==1) // If button is not pushed { Delay_ms(100); if(PORTB.F7==1) { // Repeat sequence Lcd_Out(1,4,"Total-1:"); IntToStr(var1, lcdData); Lcd_Out(1,14, lcdData); Delay_ms(500); // Print value of Var1 on screen Lcd_Out(1,4,"Total-2:"); IntToStr(var2, lcdData); Lcd_Out(1,14,lcdData); // Print value of Var2 on screen Delay_ms(500); Lcd_Out(1,4,"Total-3:"); IntToStr(var3, lcdData); Lcd_Out(1,14,lcdData); // Print value of Var3 on screen Delay_ms(500); } } else{ // If button is pressed var4=var1+var2+var3; Lcd_Out(1,3,"Gran Total:"); IntToStr(var4, lcdData); Lcd_Out(2,6,lcdData); Delay_ms(500); Lcd_Cmd(_LCD_CLEAR); } } }
void main(){
unsigned int led1=5;
unsigned int led2=3;
char ledone[17];
char ledtwo[17];
TRISA = 0xFF;
PORTA = 0x00;
TRISB = 0b11111110;
PORTB = 0b00000000;
TRISD = 0X00;
PORTD = 0X00;
Lcd_Init(); // Initialize Lcd
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
while(1){
if(PORTB.F7==1) // If button is not pushed
{
Delay_ms(100);
if(PORTB.F7==1)
{
Lcd_Out(1,1,"LED1:");
Lcd_Out(1,12,"LED2:");
IntToStr(led1, ledone);
IntToStr(led2, ledtwo);
Lcd_Out(2,1, ledone);
Lcd_Out(2,15, ledtwo);
}
}
else{ // If button is pressed
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,5,"ON");
Delay_ms(500);
Lcd_Cmd(_LCD_CLEAR);
}
}
}
Code C - [expand] 1 2 Ltrim(ledone); Ltrim(ledtwo);
void main(){
unsigned int led1=1;
unsigned int led2=2;
char tmp[17]="0";
char tmp2[17];
char ledone[17];
char tmp3[17]="0";
char tmp4[17];
char ledtwo[17];
TRISA = 0xFF;
PORTA = 0x00;
TRISB = 0b11111110;
PORTB = 0b00000000;
TRISD = 0X00;
PORTD = 0X00;
Lcd_Init(); // Initialize Lcd
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
while(1){
if(PORTB.F7==1) // If button is not pushed
{
Delay_ms(100);
if(PORTB.F7==1)
{ // Repeat sequence
Lcd_Out(1,1,"LED1");
Lcd_Out(1,13,"LED2");
memset(tmp2, '\0', sizeof(tmp2));
strcat(tmp2, tmp);
IntToStr(led1, ledone);
strcat(tmp2, ledone);
LCD_Out(2,1, tmp2);
memset(tmp4, '\0', sizeof(tmp4));
strcat(tmp4, tmp3);
IntToStr(led2, ledtwo);
strcat(tmp4, ledtwo);
LCD_Out(2,15, ledtwo);
}
}
else{ // If button is pressed
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"((TOGGLE))");
Delay_ms(500);
Lcd_Cmd(_LCD_CLEAR);
}
}
}
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 memset(tmp2, '\0', sizeof(tmp2)); strcat(tmp2, tmp); IntToStr(led1, ledone); Ltrim(ledone); strcat(tmp2, ledone); LCD_Out(2,1, tmp2); memset(tmp3, '\0', sizeof(tmp4)); strcat(tmp3, tmp); IntToStr(led2, ledtwo); Ltrim(ledtwo); strcat(tmp3, ledtwo); LCD_Out(2,15, ledtwo);
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?