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

UART from CPU and Hyper terminal not working right.
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
nailuy



Joined: 21 Sep 2010
Posts: 159

View user's profile Send private message

UART from CPU and Hyper terminal not working right.
PostPosted: Fri Apr 01, 2016 3:08 pm     Reply with quote

Hy.
I try to show on display the ascii code or simple character pressed on keyboard.
Program used is Hyper Terminal.

Code:
#use delay(internal=1MHz)//,restart_wdt)
#use rs232(baud=2400, parity=N, xmit=PIN_C7, rcv=PIN_C6, bits=8, ERRORS)

if(kbhit()) {
x=kbd_getc();}
LCD_DATA_3=133;
printf(LCD_SEND_C,"%ld",x);


Someone can help me to make this code work?
Thank you!
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Apr 01, 2016 4:08 pm     Reply with quote

What you've posted is NOT a complete program and we don't know what PIC or other hardware your using.
Basic PIC101.... we need a complete program, confirmation that a 1Hz LED program functions properly and what interface to PC you have. Also you appear to have an LCD module,so what driver are you using for that device.

We need a LOT more information before we can say it's 'this' or 'that' as to waht you're doing wrong.

Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 01, 2016 4:15 pm     Reply with quote

Quote:

I try to show on display the ascii code or simple character pressed on keyboard.

printf(LCD_SEND_C,"%ld",x);

You are using the printf format string to display a decimal number.
You want to display a character.

Download the CCS manual:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
Go to the printf section and look at the available format strings. One of
them is for printing characters. Use it instead of %ld.
nailuy



Joined: 21 Sep 2010
Posts: 159

View user's profile Send private message

PostPosted: Sat Apr 02, 2016 10:56 am     Reply with quote

Code:
while(TRUE)
   {
delay_ms (100);
lcd_init_1();
delay_ms (500);

if(kbhit()) {
x=kbd_getc();}
LCD_DATA_3=133;
printf(LCD_SEND_C,"%ld",x);
printf("\r\n Test");
    }


in header is:
Code:
#include <16F1788.h>
#device ADC=16

#FUSES PUT           //Power Up Timer
#FUSES NOMCLR        //Master Clear pin used for I/O
#FUSES NOWDT
#FUSES PROTECT       //Code protected from reads
#FUSES CPD           //Data EEPROM Code Protected
#FUSES BROWNOUT_NOSL //Brownout enabled during operation, disabled during SLEEP
#FUSES NOCLKOUT      //I/O function on OSC2
#FUSES IESO          //Internal External Switch Over mode enabled
#FUSES FCMEN         //Fail-safe clock monitor enabled
#FUSES WRT           //Program Memory Write Protected
#FUSES NOVCAP        //VCAP pin disabled
#FUSES STVREN        //Stack full/underflow will cause reset
//#FUSES BORV19        //Brownout reset at 1.9V
#FUSES LPBOR         //Low-Power Brownout reset is enabled
#FUSES NOLVP         //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O

#use delay(internal=1MHz)//,restart_wdt)
#use rs232(baud=2400, parity=N, xmit=PIN_C7, rcv=PIN_C6, bits=8, ERRORS)//, stream=PORT1, restart_wdt)

//#define int64 long long
#define LCD_DAT4   PIN_B5  //
#define LCD_DAT5   PIN_B4  //
#define LCD_DAT6   PIN_C5  //B7 / C5
#define LCD_DAT7   PIN_C4  //B6 / C4

#define LCD_E     PIN_A1
#define LCD_RS    PIN_A0
static unsigned int16 X;


this are code used by me.
Can you help me?


Last edited by nailuy on Sat Apr 02, 2016 12:35 pm; edited 1 time in total
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Apr 02, 2016 11:44 am     Reply with quote

please use code[] button when posting code....

1) do NOT enable the 'protect' fuse unless you're delivering product to client.
2) do NOT use 'restart_wdt' in #use RS232() or elsewhere unless you're code is 100% working WITHOUT it.

3) you define LCD pins, lcd_init_1() function but do not show the LCD driver.....

4) have to ask why just 1 MHz clock speed ?


Jay
nailuy



Joined: 21 Sep 2010
Posts: 159

View user's profile Send private message

PostPosted: Sat Apr 02, 2016 12:43 pm     Reply with quote

Thank you
LCD_init_1 is initiate for my LCD with my header.
LCD have no problem is working.
problem is from if(kbhit())
show on display only when i close connection, so is not normal.
How to have X=getc()?
Nailuy
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Apr 02, 2016 1:47 pm     Reply with quote

this line...
x=kbd_getc();}

means you have a keyboard device AND a driver for it, but you do not have that shown in your program

it's a similar problem with your LCD code. You call LCD functions but never show where they are loaded into your program.

My conclusion is that you are 'cut and pasting' bits of your code and NOT showing us the complete program as it cannot work as you've posted.

I cannot help any further without seeing your real program.

Jay
nailuy



Joined: 21 Sep 2010
Posts: 159

View user's profile Send private message

PostPosted: Sun Apr 03, 2016 12:16 am     Reply with quote

Dear Temtronic.
LCD is one header and have no problem with him.
kbd_getc()
I make search on forum and I found... behind I do not have any code. That's why is not working probably.
I need your help to understand how to use or how to build code.
getc()
is simple command to get data from hyper terminal, is working when I close connection, and show last keyboard pressed sometime.
Thank you.
Nailuy.
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Apr 03, 2016 5:19 am     Reply with quote

getc() is in the CCS manual. Press F11 with your project open and the CCS manual magically 'pops up'. I usually keep it open and minimized to quickly access it for obvious reasons!
CCS also kindly supplies LOTS of example programs that use getc() in additon to a good fact sheet on how to use it, in the manual.

kbd_getc() is a derivation of getc(), created to get a character from a keyboard. How it is used depends on the user's choice of keyboard,PIC /KBD interface and requirements for translation.

If you do NOT have a keyboard or keypad do NOT use kbd_getc() !



Jay
nailuy



Joined: 21 Sep 2010
Posts: 159

View user's profile Send private message

PostPosted: Sun Apr 10, 2016 1:30 pm     Reply with quote

Hi Temtronic.
I made special code only for test.
In main is:
Code:
#include <16F1788_test.h>

void main()
{
VAR1=356;
while(TRUE)
{
T3++;
if (T3==1000){            //65535
   T3=0;
   putc('\n');
   putc('\r');
   printf("%Lu",VAR1);

   if(kbhit()) {
   KEY2=getc();}
   putc('\n');
   putc('\r');
   printf("%ld",KEY2);
   }
}
}


and in header:
Code:
#include <16F1788.h>
#device ADC=16

#FUSES NOPUT                    //No Power Up Timer
//#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOMCLR
#FUSES PROTECT                  //Code protected from reads
#FUSES CPD                      //Data EEPROM Code Protected
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOCLKOUT                 //I/O function on OSC2
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES WRT                      //Program Memory Write Protected
#FUSES NOVCAP                   //VCAP pin disabled
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES BORV19                   //Brownout reset at 1.9V
#FUSES NOLPBOR                  //Low-Power Brownout reset is disabled
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O

#use delay(internal=1MHz,restart_wdt)
#use rs232(baud=2400,parity=N,xmit=PIN_C7,rcv=PIN_C6,bits=8,stream=P1)


static unsigned int16 VAR1;   //
#locate VAR1 = 0x070

static unsigned int16 KEY2;   //
#locate KEY2 = 0x072

static unsigned int16 T3;   //
#locate T3 = 0x074


Are working:
VAR1 is sending by serial hex values:
0A 0D 33 35 36 0A 0D 30 and is repeating... so is okay all.
all are fine as ASCII code.
T3 is indexing

Are not working:
KEY2 every value sent as hex or char are as zeo received back
Code:
 if(kbhit()) {
   KEY2=getc();}

how can I make this work?
best regards.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 11, 2016 3:04 pm     Reply with quote

First try a simple program to see if everything works. This program
echoes anything it receives back to the PC. Try it. Do you see what
you type in the terminal program window ?
Code:

#include <16F1788.h>
#fuses INTRC_IO, NOWDT
#use delay(clock=1M)
#use rs232(baud=2400, UART1, ERRORS)

//==========================================
void main()
{   
int8 value;
   
while(TRUE)   
  {
   if(kbhit())  // Was a key pressed on PC keyboard ?
     {
      value = getc();  // If so, get it from UART
      putc(value);     // Then send it back to terminal program
     }
  }

}
nailuy



Joined: 21 Sep 2010
Posts: 159

View user's profile Send private message

PostPosted: Tue Apr 12, 2016 10:55 am     Reply with quote

Dear PCM programmer
Thank you.

I make some changes:
I don't have pull up for MCLR externally so I set it to be internally.
Code not works and I changed to send continuously data and still not working.
So code:
Code:
#include <16F1788_test2.h>

void main()
 {   
 int8 value;
     
 while(TRUE)   
   {
   putc(8);     // I put this row to see which pin is TX from  UART
//    if(kbhit())  // Was a key pressed on PC keyboard ?
//      {
//       value = getc();  // If so, get it from UART
//       putc(value);     // Then send it back to terminal program
//      }
   }

 }
///////////////////////////////////////////////////////////////////////////////
#include <16F1788.h>
#fuses INTRC_IO, NOWDT
#FUSES NOMCLR

#use delay(clock=1M)
#use rs232(baud=2400, UART1, ERRORS)


I look at pins B7, B6, C7 and C6 none of them transmit data.
But my program transmit data in okay mode...
so?
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Tue Apr 12, 2016 1:34 pm     Reply with quote

Hi,

On that PIC, the Rx pin is RC7, and the Tx pin is RC6. This is 'UART1'. The other pins, RB7 & RB6 are an alternate set of pins for the UART, but they should not be active in your situation.

Now, the UART can send data on the Tx pin, and receive data on the Rx pin. Based on your previous posts, it sounds like you can send data to HyperTerminal (PIC --> PC), right? The problem is that you cannot receive data from HyperTerminal (PC --> PIC), also correct?

The next step, is to tell us what you have connected between the PIC UART pins and your PC. Are you using a MAX232 type device, or a USB-to-TTL converter perhaps?

What is the Vcc voltage of your PIC?

If you are using a USB-to-TTL converter, post a link to the datasheet!
_________________
John

If it's worth doing, it's worth doing in real hardware!
nailuy



Joined: 21 Sep 2010
Posts: 159

View user's profile Send private message

PostPosted: Tue Apr 12, 2016 3:00 pm     Reply with quote

Hy
Is correct all you say PC->PIC, PIC->PC.
Also I tested by making short circuit on USB TTL converter pin no 7 an 8.
and hyper terminal work OK.
Device used is UB232R and datasheet is:
http://www.google.ro/url?url=http://www.ftdichip.com/Documents/DataSheets/Modules/DS_UB232R.pdf&rct=j&q=&esrc=s&sa=U&ved=0ahUKEwjK-Lba_YnMAhUSKywKHWkdDOgQFggeMAA&sig2=z-iBzDiNK_eczyyMnbG_qg&usg=AFQjCNHy69-I7AHy34jXzTpkPIk1kBEKNg
and J3 is connected to 1-2.

interesting now is why with this simple code
putc(8);
now is not sending, maybe compiler or PIC do not recognize hardware UART?
when I set by software pin for RX and pin for TX is works...
Best regards.
nailuy



Joined: 21 Sep 2010
Posts: 159

View user's profile Send private message

PostPosted: Tue Apr 12, 2016 3:14 pm     Reply with quote

I'm back with one discovery.
When I set by software pin for RX and pin for TX, pin the same like are UART hardware compiler recognize and is not working, when I change between them or any other pin is working so is not normally....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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