CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

why function in loop while(1) is not work? Please help me.

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
a
Guest







why function in loop while(1) is not work? Please help me.
PostPosted: Thu Jan 06, 2005 4:31 am     Reply with quote

below is my sourcecode. i'm very confuse about why function in loop while is not work.

i'm try do...while(1) and while(1). it's not work. Sad Sad


#include <16F876.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=3579545)

#use rs232(baud=9600, parity=N,xmit=PIN_B7,rcv=PIN_B7,bits=9)

#bit ninth_bit = RS232_ERRORS.7
#bit collision = RS232_ERRORS.6
#bit intf = 11.1

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <input.c>

#define RW PIN_A0
#define RS PIN_A1
#define EN PIN_A2

#define LED0 PIN_A3
#define LED1 PIN_A4
byte cou;
byte tmpsc[6];
int cloop,counterr;
int countloop;
int cerror;
long numchartrue=0;
long numcharfalse=0;
long countloopwhile=0;

void out_led(int i_led)
{
switch(i_led) // before after
{ // 4 3 4 3
case 0 : { output_high(LED1); output_low(LED0); break; } // 0 0 1 0
case 1 : { output_high(LED1); output_high(LED0); break; } // 0 1 1 1
case 2 : { output_low(LED1); output_low(LED0); break; } // 1 0 0 0
case 3 : { output_low(LED1); output_high(LED0); break; } // 1 1 0 1
default : { break; }
//because PIN_A4 is open Drain output must be toggle from it should be
}
}
//========================================LCD==================================
void busy_strobe(void)
{
OUTPUT_LOW(EN);
delay_us(2);
OUTPUT_HIGH(EN);
delay_us(2);
}

void write_strobe(void)
{
OUTPUT_HIGH(EN);
delay_us(2);
OUTPUT_LOW(EN);
delay_us(2);
}

void Command(void)
{
OUTPUT_LOW(RS);
OUTPUT_LOW(RW);
}

void wait_for_lcd_ready(void)
{
unsigned char busy_flag;

SET_TRIS_C(0XFF); //PORTD7 INPUT;
OUTPUT_LOW(RS); //SET FOR READ BUSY;
OUTPUT_HIGH(RW); //SET FOR READ BUSY;

busy_strobe();
busy_flag=(input_C() & 0x80);

while( busy_flag == 0x80)
{
OUTPUT_LOW(EN);
busy_strobe();
busy_flag=(input_C()&0x80);
}

OUTPUT_LOW(EN);

SET_TRIS_C(0x00); //PORTD7 OUTPUT;
}

void clear_lcd(void)
{
Command();
OUTPUT_C(0x01);
write_strobe();
wait_for_lcd_ready();
}

void cursor_off(void)
{
Command();
OUTPUT_C(0x0c);
write_strobe();
wait_for_lcd_ready();
}

void init_lcd(void)
{
Command(); //add 240847
OUTPUT_C(0x38); //add 240847
write_strobe(); //add 240847
delay_ms(5); //add 240847

Command();
OUTPUT_C(0x38);
write_strobe();
delay_us(120); //add 240847

Command();
OUTPUT_C(0x0f);
write_strobe();
wait_for_lcd_ready();

clear_lcd();

Command();
OUTPUT_C(0x02);
write_strobe();
wait_for_lcd_ready();

cursor_off();
}

void Wchar(unsigned char char_)
{
OUTPUT_HIGH(RS);
OUTPUT_LOW(RW);

OUTPUT_C(char_);
write_strobe();
wait_for_lcd_ready();
}

void gotoxy(unsigned char row,unsigned char col)
{
Command();
if (row==1) OUTPUT_C(0x80+col-1);
else
if (row==2) OUTPUT_C(0xc0+col-1);
write_strobe();
wait_for_lcd_ready();
}

void Wcharxy(unsigned char row,unsigned char col,unsigned char data_)
{
gotoxy(row,col);
Wchar(data_);
}

void string_to_lcd(unsigned char row,unsigned char col,unsigned char *st)
{
unsigned char i,len;

len=strlen(st);
if (len>20) len=20;
gotoxy(row,col);
for(i=0;i<=len-1;i++)
{
Wchar(st[i]);
}
}

void int_to_lcd(unsigned char row,unsigned char col,int data_int)
{
unsigned char str[7];

sprintf(str,"%d",data_int);
string_to_lcd(row,col,str);
}

void long_to_lcd(unsigned char row,unsigned char col,long data_long)
{
unsigned char str[7];

sprintf(str,"%ld",data_long);
string_to_lcd(row,col,str);
}

void hex_to_lcd(unsigned char row,unsigned char col,unsigned char data_hex)
{
unsigned char str[3];

sprintf(str,"%x",data_hex);
string_to_lcd(row,col,str);
}

void float_to_lcd(unsigned char row,unsigned char col,float data_float)
{
unsigned char str[7];

sprintf(str,"%02.1f",data_float);
string_to_lcd(row,col,str);
}
//==========================================================================================

int8 find_parity(int8 data)
{
#asm
swapf data, W
xorwf data, F
rrf data, W
xorwf data, F
btfsc data, 2
incf data, F
movf data, W
andlw 1
movwf _return_
#endasm
}

void pbus_write(byte cha)
{
BYTE checksum,i;
int count,evencheck;
long cycles;
int er;

wcharxy(2,1,cha);
hex_to_lcd(2,10,cha);
delay_ms(200);

retry:
disable_interrupts(GLOBAL);

if(find_parity(cha)==0) { ninth_bit=0; }
else if(find_parity(cha)==1) { ninth_bit=1; }

putc(cha);

for(cycles=0;cycles<=2;cycles++)
{
if( !input(PIN_B7) )
{
goto error;
}
}
enable_interrupts(GLOBAL);
return;

error:
delay_us(100);
enable_interrupts(GLOBAL);
goto retry;
}

#int_RB
void checkserial(void)
{
byte data;

if(kbhit())
{
data=getc();

if (find_parity(data) == ninth_bit)
{
numchartrue++;
long_to_lcd(1,10,numchartrue);
}
else
{
output_low(PIN_B7); delay_us(50); output_high(PIN_B7);
numcharfalse++;
}
}
}

void main(void)
{
BYTE to,i,value;
char xxx[10]="ABCD";

counterr=0;
countloop=0;
cerror=0;

port_b_pullups(TRUE);
output_high(PIN_B7);
init_lcd();

enable_interrupts(global);
enable_interrupts(int_rb);

do
{
string_to_lcd(1,1,xxx);
delay_ms(100);
} while(1);


// while(1)
// {
// string_to_lcd(1,1,xxx);
// delay_ms(100);
// }

}
Sad
Guest








Now it is ok
PostPosted: Thu Jan 06, 2005 7:16 am     Reply with quote

i must disable_interrupts(int_rb)
before loop while
Ttelmah
Guest







Re: Now it is ok
PostPosted: Thu Jan 06, 2005 9:52 am     Reply with quote

Anonymous wrote:
i must disable_interrupts(int_rb)
before loop while

Sounds as though the serial input line is floating low at the processor. How is this wired?. If this line is low, the chip will generate continuous serial receive interrupts, and pretty nearly hang...

Best Wishes
a
Guest







PostPosted: Thu Jan 06, 2005 8:56 pm     Reply with quote

i used R-pull up ready. but it still disable_interrupt(int_rb);
thank you for your reply
Ttelmah
Guest







PostPosted: Fri Jan 07, 2005 4:02 am     Reply with quote

Check with a voltmeter, that the line is high at the processor. It really sounds too suspiciously like this line being seen as a low... :-)

Best Wishes
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Jan 07, 2005 7:24 am     Reply with quote

Code:
output_high(PIN_B7);


Hum, doesn't this make the pin an output? But yet you are also using it as an input. Also, int_rb is more than just RB7. So "other things" could be causing this int to occur.
Guest








PostPosted: Thu Feb 24, 2005 5:59 pm     Reply with quote

Quote:
[#use rs232(baud=9600, parity=N,xmit=PIN_B7,rcv=PIN_B7,bits=9)]


Looks like your xmit and rcv pin are the same pin! :([/quote]
Guest








PostPosted: Thu Feb 24, 2005 6:00 pm     Reply with quote

Quote:
#use rs232(baud=9600, parity=N,xmit=PIN_B7,rcv=PIN_B7,bits=9)


Looks like your xmit and rcv pin are the same pin! :(
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group