Микроконтролери и електроника
http://mcu-bg.com/mcu_site/

pic16f877a,HD44780 и отново проблем с mplab и ccs
http://mcu-bg.com/mcu_site/viewtopic.php?f=3&t=7436
Страница 1 от 1

Автор:  kalinskia [ Нед Яну 03, 2010 2:52 am ]
Заглавие:  pic16f877a,HD44780 и отново проблем с mplab и ccs

В проекта имам два файла:
main.c :

#include "16F877A.h"

#use delay(clock=4000000)
#fuses NOWDT,XT, NOPUT, NOPROTECT

#use rs232(baud=9600, xmit=PIN_A0, rcv=PIN_A1)

#define DS1307_SDA PIN_C4
#define DS1307_SCL PIN_C3
#use i2c(master, sda=PIN_C4, scl=PIN_C3)


#include <LCD.C>

//==========================
// initial DS1307
//==========================
void init_DS1307()
{
output_float(DS1307_SCL);
output_float(DS1307_SDA);
}
//==========================
// write data one byte to
// DS1307
//==========================
void write_DS1307(byte address, BYTE data)
{
short int status;
i2c_start();
i2c_write(0xd0);
i2c_write(address);
i2c_write(data);
i2c_stop();
i2c_start();
status=i2c_write(0xd0);
while(status==1)
{
i2c_start();
status=i2c_write(0xd0);
}
}
//==========================
// read data one byte from DS1307
//==========================
BYTE read_DS1307(byte address)
{
BYTE data;
i2c_start();
i2c_write(0xd0);
i2c_write(address);
i2c_start();
i2c_write(0xd1);
data=i2c_read(0);
i2c_stop();
return(data);
}



void main(void)
{

int8 sec,min,hour,day,date,month,year;
lcd_init();
delay_ms(50);
init_ds1307(); // initial DS1307
sec=read_ds1307(0);
write_ds1307(0,sec & 0x7F); // enable oscillator(bit 7 =0)

while(true)
{
sec=read_ds1307(0); // read second
min=read_ds1307(1); // read minute
hour=read_ds1307(2); // read hour
day=read_ds1307(3); // read day
date=read_ds1307(4); // read date
month=read_ds1307(5); // read month
year=read_ds1307(6); // read year
putc(254);putc(1);
printf(" Time: %02X:%02X:%02X",hour,min,sec);
putc(254);putc(192);
printf("Date: %02X/%02X/20%02X",date,month,year);
delay_ms(500);
}
}


и lcd.c :

///////////////////////////////////////////////////////////////////////////
//// LCDD.C ////
//// Driver for common LCD modules ////
//// ////
//// lcd_init() Must be called before any other function. ////
//// ////
//// lcd_putc(c) Will display c on the next position of the LCD. ////
//// The following have special meaning: ////
//// \f Clear display ////
//// \n Go to start of second line ////
//// \b Move back one position ////
//// ////
//// lcd_gotoxy(x,y) Set write position on LCD (upper left is 1,1) ////
//// ////
//// lcd_getc(x,y) Returns character at position x,y on LCD ////
//// ////
///////////////////////////////////////////////////////////////////////////
//// (C) Copyright 1996,2003 Custom Computer Services ////
//// This source code may only be used by licensed users of the CCS C ////
//// compiler. This source code may only be distributed to other ////
//// licensed users of the CCS C compiler. No other use, reproduction ////
//// or distribution is permitted without written permission. ////
//// Derivative programs created using this software in object code ////
//// form are not restricted in any way. ////
///////////////////////////////////////////////////////////////////////////

// As defined in the following structure the pin connection is as follows:
// D0 enable
// D1 rs
// D2 rw
// D4 D4
// D5 D5
// D6 D6
// D7 D7
//
// LCD pins D0-D3 are not used and PIC D3 is not used.

// Un-comment the following define to use port B
#define use_portb_lcd TRUE


struct lcd_pin_map {
BOOLEAN unused1; // For RB0
BOOLEAN unused2; // For RB1
BOOLEAN enable; // For RB2
BOOLEAN rs; // For RB3
int data : 4; // For RB4-RB7
} lcd;


#if defined(__PCH__)
#if defined use_portb_lcd
#byte lcd = 0xF81 // This puts the entire structure
#else
#byte lcd = 0xF83 // This puts the entire structure
#endif
#else
#if defined use_portb_lcd
#byte lcd = 6 // on to port B (at address 6)
#else
#byte lcd = 8 // on to port D (at address 8)
#endif
#endif

#if defined use_portb_lcd
#define set_tris_lcd(x) set_tris_b(x)
#else
#define set_tris_lcd(x) set_tris_d(x)
#endif


#define lcd_type 2 // 0=5x7, 1=5x10, 2=2 lines
#define lcd_line_two 0x40 // LCD RAM address for the second line


BYTE const LCD_INIT_STRING[4] = {0x20 | (lcd_type << 2), 0xc, 1, 6};
// These bytes need to be sent to the LCD
// to start it up.


// The following are used for setting
// the I/O port direction register.

struct lcd_pin_map const LCD_WRITE = {0,0,0,0,0}; // For write mode all pins are out
struct lcd_pin_map const LCD_READ = {0,0,0,0,15}; // For read mode data pins are in



BYTE lcd_read_byte() {
BYTE low,high;
set_tris_lcd(LCD_READ);
lcd.rw = 1;
delay_cycles(1);
lcd.enable = 1;
delay_cycles(1);
high = lcd.data;
lcd.enable = 0;
delay_cycles(1);
lcd.enable = 1;
delay_us(1);
low = lcd.data;
lcd.enable = 0;
set_tris_lcd(LCD_WRITE);
return( (high<<4) | low);
}


void lcd_send_nibble( BYTE n ) {
lcd.data = n;
delay_cycles(1);
lcd.enable = 1;
delay_us(2);
lcd.enable = 0;
}


void lcd_send_byte( BYTE address, BYTE n ) {

lcd.rs = 0;
while ( bit_test(lcd_read_byte(),7) ) ;
lcd.rs = address;
delay_cycles(1);
lcd.rw = 0;
delay_cycles(1);
lcd.enable = 0;
lcd_send_nibble(n >> 4);
lcd_send_nibble(n & 0xf);
}


void lcd_init() {
BYTE i;
set_tris_lcd(LCD_WRITE);
lcd.rs = 0;
lcd.rw = 0;
lcd.enable = 0;
delay_ms(15);
for(i=1;i<=3;++i) {
lcd_send_nibble(3);
delay_ms(5);
}
lcd_send_nibble(2);
for(i=0;i<=3;++i)
lcd_send_byte(0,LCD_INIT_STRING[i]);
}


void lcd_gotoxy( BYTE x, BYTE y) {
BYTE address;

if(y!=1)
address=lcd_line_two;
else
address=0;
address+=x-1;
lcd_send_byte(0,0x80|address);
}

void lcd_putc( char c) {
switch (c) {
case '\f' : lcd_send_byte(0,1);
delay_ms(2);
break;
case '\n' : lcd_gotoxy(1,2); break;
case '\b' : lcd_send_byte(0,0x10); break;
default : lcd_send_byte(1,c); break;
}
}

char lcd_getc( BYTE x, BYTE y) {
char value;

lcd_gotoxy(x,y);
while ( bit_test(lcd_read_byte(),7) ); // wait until busy flag is low
lcd.rs=1;
value = lcd_read_byte();
lcd.rs=0;
return(value);
}


Проблемът е , че компилатора ми дава тази грешка "Error 128 "LCD.C" Line 42(1,6): A #DEVICE required before this line
C:\Users\Kalin\Desktop\LCD.o ===> 1 Errors, 0 Warnings."
на реда "struct lcd_pin_map {"

Много Ви моля за помощ!!!

Автор:  valioman [ Нед Яну 03, 2010 3:44 pm ]
Заглавие: 

Пробвай този код за драйвер

Код:


#define LCD_DB4   PIN_C2
#define LCD_DB5   PIN_C3
#define LCD_DB6   PIN_C4
#define LCD_DB7   PIN_C5

#define LCD_E     PIN_C1
#define LCD_RS    PIN_C0
//#define LCD_RW    PIN_B2

// If you only want a 6-pin interface to your LCD, then
// connect the R/W pin on the LCD to ground, and comment
// out the following line.

//#define USE_LCD_RW   1     

//========================================

#define lcd_type 2        // 0=5x7, 1=5x10, 2=2 lines
#define lcd_line_two 0x40 // LCD RAM address for the 2nd line


int8 const LCD_INIT_STRING[4] =
{
0x20 | (lcd_type << 2), // Func set: 4-bit, 2 lines, 5x8 dots
0xc,                    // Display on
1,                      // Clear display
6                       // Increment cursor
};
                             

//-------------------------------------
void lcd_send_nibble(int8 nibble)
{
// Note:  !! converts an integer expression
// to a boolean (1 or 0).
output_bit(LCD_DB4, !!(nibble & 1));
output_bit(LCD_DB5, !!(nibble & 2));
output_bit(LCD_DB6, !!(nibble & 4));   
output_bit(LCD_DB7, !!(nibble & 8));   

delay_cycles(1);
output_high(LCD_E);
delay_us(2);
output_low(LCD_E);
}

//-----------------------------------
// This sub-routine is only called by lcd_read_byte().
// It's not a stand-alone routine.  For example, the
// R/W signal is set high by lcd_read_byte() before
// this routine is called.     

#ifdef USE_LCD_RW
int8 lcd_read_nibble(void)
{
int8 retval;
// Create bit variables so that we can easily set
// individual bits in the retval variable.
#bit retval_0 = retval.0
#bit retval_1 = retval.1
#bit retval_2 = retval.2
#bit retval_3 = retval.3

retval = 0;
   
output_high(LCD_E);
delay_cycles(1);

retval_0 = input(LCD_DB4);
retval_1 = input(LCD_DB5);
retval_2 = input(LCD_DB6);
retval_3 = input(LCD_DB7);

output_low(LCD_E);
   
return(retval);   
}   
#endif

//---------------------------------------
// Read a byte from the LCD and return it.

#ifdef USE_LCD_RW
int8 lcd_read_byte(void)
{
int8 low;
int8 high;

output_high(LCD_RW);
delay_cycles(1);

high = lcd_read_nibble();

low = lcd_read_nibble();

return( (high<<4) | low);
}
#endif

//----------------------------------------
// Send a byte to the LCD.
void lcd_send_byte(int8 address, int8 n)
{
output_low(LCD_RS);

#ifdef USE_LCD_RW
while(bit_test(lcd_read_byte(),7)) ;
#else
delay_us(60);
#endif

if(address)
   output_high(LCD_RS);
else
   output_low(LCD_RS);
     
delay_cycles(1);

#ifdef USE_LCD_RW
output_low(LCD_RW);
delay_cycles(1);
#endif

output_low(LCD_E);

lcd_send_nibble(n >> 4);
lcd_send_nibble(n & 0xf);
}

//----------------------------
void lcd_init(void)
{
int8 i;

output_low(LCD_RS);

#ifdef USE_LCD_RW
output_low(LCD_RW);
#endif

output_low(LCD_E);

delay_ms(15);

for(i=0 ;i < 3; i++)
   {
    lcd_send_nibble(0x03);
    delay_ms(5);
   }

lcd_send_nibble(0x02);

for(i=0; i < sizeof(LCD_INIT_STRING); i++)
   {
    lcd_send_byte(0, LCD_INIT_STRING[i]);
   
    // If the R/W signal is not used, then
    // the busy bit can't be polled.  One of
    // the init commands takes longer than
    // the hard-coded delay of 60 us, so in
    // that case, lets just do a 5 ms delay
    // after all four of them.
    #ifndef USE_LCD_RW
    delay_ms(5);
    #endif
   }

}

//----------------------------

void lcd_gotoxy(int8 x, int8 y)
{
int8 address;

if(y != 1)
   address = lcd_line_two;
else
   address=0;

address += x-1;
lcd_send_byte(0, 0x80 | address);
}

//-----------------------------
void lcd_putc(char c)
{
switch(c)
   {
    case '\f':
      lcd_send_byte(0,1);
      delay_ms(2);
      break;
   
    case '\n':
       lcd_gotoxy(1,2);
       break;
   
    case '\b':
       lcd_send_byte(0,0x10);
       break;
   
    default:
       lcd_send_byte(1,c);
       break;
   }
}

//------------------------------
#ifdef USE_LCD_RW
char lcd_getc(int8 x, int8 y)
{
char value;

lcd_gotoxy(x,y);

// Wait until busy flag is low.
while(bit_test(lcd_read_byte(),7));

output_high(LCD_RS);
value = lcd_read_byte();
output_low(lcd_RS);

return(value);
}
#endif


Автор:  kalinskia [ Нед Яну 03, 2010 5:38 pm ]
Заглавие: 

Все същата грешка...

Автор:  valioman [ Нед Яну 03, 2010 6:24 pm ]
Заглавие: 

kalinskia написа:
Все същата грешка...

При мен си се компилира без проблеми .. скоя версия на CCS-a си?

Прикачени файлове:
Коментар на файл: ccs
proba.JPG
proba.JPG [ 110.75 KiB | Прегледано 3235 пъти ]

Автор:  darkshy [ Нед Яну 03, 2010 7:11 pm ]
Заглавие: 

valiomen, той човека е писал, че под mplab-а не му работи кода. Може в ccs-a да му работи :)
Междудругото тя коя е тази бъгавата версия на ццс-а, защото и на мен доста пъти неще да компилирва и са бъгясва :?
Мойта е: 4.084

Автор:  kalinskia [ Нед Яну 03, 2010 7:19 pm ]
Заглавие: 

Вече и за незнам с коя версия съм , сменям ги постоянно , като си мисля че е от това. Можете ли да дадете някоя читава версия?

Автор:  kalinskia [ Нед Яну 03, 2010 8:21 pm ]
Заглавие: 

Установих,че тази грешка ми я дава, когато съм добавил файла lcd.c към проекта. Когато го премагна програмата се компилира. Когато пусна стъпка по стъпка да се изпълнява програмата след функцията lcd_init(); се отваря файла lcd.c , незнайно от къде, пише , че се намира в C:\Program Files\PICC\Devices , но когато този файл го променя, не вийдам промените в mplaba.

Автор:  RM [ Пон Яну 04, 2010 12:23 pm ]
Заглавие: 

Една от последните версии е CCS 4.093.Когато се инсталира , мисля че имаше плъгин за MPLAB ... но не съм го ползвал.

Автор:  bobyper [ Пон Яну 04, 2010 12:24 pm ]
Заглавие: 

Гледам че в твоя случай си писал така

#include "16F877A.h"

а не така
#include <16F877A.h>

което ще рече че отваряш 16F877A.h от текущата папка. Та в този файл не си показал какво има и явно там няма дефинициите за процесора

Автор:  kalinskia [ Вто Яну 05, 2010 10:45 am ]
Заглавие: 

bobyper написа:
Гледам че в твоя случай си писал така

#include "16F877A.h"

а не така
#include <16F877A.h>

което ще рече че отваряш 16F877A.h от текущата папка. Та в този файл не си показал какво има и явно там няма дефинициите за процесора


Нямаше промяна при #include <16F877A.h>. Процедирам по следния начин: довавям файла(за да знае компилатора в последствие от къде да го дръпне), изкарва ми "Error 128 "LCD.C" Line 42(1,6): A #DEVICE required before this line , след което премахвам lcd.c от проекта и програмата се компилира.Въпросът остава все още без отговор.

Автор:  fan [ Вто Яну 05, 2010 11:18 am ]
Заглавие: 

Последната версия е тук:
PCWHD 4.104
http://www.sonsivri.com/forum/index.php?topic=26878.0

Автор:  RM [ Вто Яну 05, 2010 3:22 pm ]
Заглавие: 

Че е там там е , но май няма да я види. Постни линковете с упдейт фаиловете за да си я изтегли 8O

Автор:  fan [ Вто Яну 05, 2010 3:41 pm ]
Заглавие: 

Ще се регистрира ако иска да я види! Хубаво е да си пазим форума от проблеми!

Автор:  zle [ Нед Яну 29, 2012 7:40 pm ]
Заглавие:  Re: pic16f877a,HD44780 и отново проблем с mplab и ccs

И аз имам същия проблем може ли малко инфо?

Автор:  Stoimen [ Нед Яну 29, 2012 9:07 pm ]
Заглавие:  Re: pic16f877a,HD44780 и отново проблем с mplab и ccs

http://www.ccsinfo.com/forum/viewtopic.php?t=34046

Страница 1 от 1 Часовете са според зоната UTC + 2 часа [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/