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

Please help me about led is blink when i swap my sourcecode!

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







Please help me about led is blink when i swap my sourcecode!
PostPosted: Wed Dec 08, 2004 2:11 pm     Reply with quote

Please help me about led is blink when i swap my sourcecode!

i use PORT_A4 and PORT_A3 is led for show status
below is my sourcecode

#include <16F876.h>
#device *=16
#device adc=8
#use delay(clock=3579545)
#fuses NOWDT,XT, NOPUT, NOPROTECT, NOBROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG
#ZERO_RAM

#include<stdio.h>
#include<stdlib.h>

#use fixed_io(a_outputs=PIN_A0, PIN_A1, PIN_A2 ,PIN_A3 ,PIN_A4 ,PIN_A5)
#USE FAST_IO(A)

#define RW PIN_A0
#define RS PIN_A1
#define EN PIN_A2
#define LED0 PIN_A3
#define LED1 PIN_A4

void out_led(int i_led)
{
// disable_interrupts(INT_TIMER0);
set_tris_a(0b000000);
switch(i_led)
{
case 0 : { output_low(LED0); output_low(LED1); break; }
case 1 : { output_high(LED0); output_low(LED1); break; }
case 2 : { output_low(LED0); output_high(LED1); break; }
case 3 : { output_high(LED0); output_high(LED1); break; }
default : { break; }
}
// disable_interrupts(INT_TIMER0);
}

//========================================LCD==================================
void busy_strobe(void)
{
// set_tris_a(0b000000);
OUTPUT_LOW(EN);
delay_us(2);
OUTPUT_HIGH(EN);
delay_us(2);
}

void write_strobe(void)
{
// set_tris_a(0b000000);
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;

// disable_interrupts(INT_TIMER0);

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);
}
//==========================================================================================

void main()
{
int i;
CHAR TMPCH[16]="HELLO";

delay_ms(100);

set_tris_a(0b000000);
set_tris_c(0b00000000);

port_b_pullups(TRUE);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(FALSE);
disable_interrupts(INT_TIMER0);
// setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);

delay_ms(10);
init_lcd();
output_a(0x00);
delay_ms(10);

while(1)
{
for(i=0;i<=3;i++)
{
//=============================================
out_led(3); //not ok
STRING_TO_LCD(2,1,TMPCH);
// out_led(3); // ok
DELAY_MS(500);
//===============================================
}
}
}
in loop for(i=0;i<=3;i++) if i use out_led(3) before STRING_TO_LCD(2,1,TMPCH); output_on PIN_A4 is blink but PIN_A3 is light normal
but if i use out_led(3) after STRING_TO_LCD(2,1,TMPCH); output on PIN_A4 and PIN_A3 is light.

Please help me because i very confuse about this result.
It should have the same result between 2 sourcecode??????
a
Guest







i know.
PostPosted: Wed Dec 08, 2004 6:31 pm     Reply with quote

i know. RA4 is open drain. Logic must be toggled.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Thu Dec 09, 2004 8:07 am     Reply with quote

I for one don't understand your question. Can you write a program of 10 or 20 lines that demonstrates the problem? I don't have time to search through pages of listing when I don't know what I am looking for.
_________________
The search for better is endless. Instead simply find very good and get the job done.
myheadhurts



Joined: 08 Dec 2004
Posts: 7

View user's profile Send private message Visit poster's website

PostPosted: Thu Dec 09, 2004 8:24 am     Reply with quote

Does the string to LCD function use the same port pin? this could account for the flash of the LED
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