|
|
View previous topic :: View next topic |
Author |
Message |
Onurr Guest
|
Code is working on 16F877 but not work in 18F452 |
Posted: Thu Aug 05, 2004 2:55 am |
|
|
Fistly I'm using 16f877 I wrote a program. this program work fine on 16f877. 16f877 ram not enough for me. I changed pic 18f452.
Code: |
//#INCLUDE <16F877.h>
//#use delay(clock=20000000)
//#FUSES HS,NOWDT,NOPROTECT,NOLVP,noPUT, NOBROWNOUT
#include <18F452.h>
#use delay(clock=20000000) //when using national demo board
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOOSCSEN,NOBROWNOUT,NOSTVREN,NOPUT,NOEBTRB,NOEBTR,NOCPB,NOCPD,NOWRT,NOWRTD,NOWRTC,NOWRTB,NODEBUG
|
I changed this line .
this is the program... (you can use Treva HC-D01 camera for photo)
Code: |
#use rs232(baud=56000, xmit=PIN_E0, rcv=PIN_E1) //A0 = pin17 A1 = pin18
#INCLUDE <24256_.c>
//#define Data PIN_D1
//#define Clk PIN_D0
//#INCLUDE <2416_.c>
#use fast_io(d)
struct Portd_pin_map { // This structure is overlayed
BOOLEAN clk; // on to an I/O port to gain
BOOLEAN data; // access to the LCD pins.
} portd;
#byte portd = 8
int read_bit(void);
void main(void){
int i;
unsigned char d;
long int k;
init_ext_eeprom();
SET_TRIS_d(0b00000010);
/*
kamera pinleri
pink = clock = port1.0
yellow = data = port1.1
while(1){
if (!input(pin_c7)){
output_high(pin_e2);
/* 100bit continuation is carried out. That '1' comes It waits. */
i = 0;
while(i<100){
if( read_bit() == 1) i++;
else i = 0;
}
/* '0' for 65 bits of continuation Detection*/
i = 0;
while(i<65){
if( read_bit() == 0) i++;
else i = 0;
}
/* The data for continuing 16 bits is disregarded. */
for( i=0; i<16; i++ ){
read_bit();
}
/* From here to an image data acquisition start */
for( k=0; k < 96*72*2; k++){ // for( k=0; k < 96*72*2; k++){
d = 0;
for (i=0; i<8; i++){
d <<= 1;
if(read_bit())
d |= 0x1;
}
write_ext_eeprom(k, d);
}
output_low(pin_e2);
}
else{
/* The acquired data is transmitted to PC. */
getc();
for( k=0; k < 96*72*2; k++){
putc(read_ext_eeprom(k));
}
}
}//while
} /* main */
int read_bit(){
int i, a;
portd.clk=1;
a = portd.data; /* 1bit read-out processing DOUT is read in a */
portd.clk=0;//
if(a)
return 1;
else
return 0;
}
|
This program getting data from camera and saving data on 24c256.
This code not working on 18f452. but working on 16F877.
I added led on
for( k=0; k < 96*72*2; k++){ this loop end.
led must be turn off (when I used 16f877 led is turning off)
and getc() function dont wait a character. but 16f877 is waiting character.
I tested on
This version of compiler...
3.168
3.182
3.203
all the result same..
Please help me.
I dont know how to solve th,s problem.... |
|
|
Guest
|
|
Posted: Thu Aug 05, 2004 3:51 am |
|
|
You have a line:
#byte portd = 8
The ports are in different addresses in 18F452 (0x008 is RAM). |
|
|
Onurr Guest
|
|
Posted: Thu Aug 05, 2004 3:58 am |
|
|
ooooo yes I forgot it. You are right.. Im sorry . I will chage it.. code must be work.... |
|
|
Guest
|
|
Posted: Thu Aug 05, 2004 4:20 am |
|
|
I changed program. but Problem is continue....
Code: |
#include <18F452.h>
#use delay(clock=20000000) //when using national demo board
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOOSCSEN,NOBROWNOUT,NOSTVREN,NOPUT,NOEBTRB,NOEBTR,NOCPB,NOCPD,NOWRT,NOWRTD,NOWRTC,NOWRTB,NODEBUG
#use rs232(baud=56000, xmit=PIN_E0, rcv=PIN_E1)
#INCLUDE <24256_.c>
|
Code: |
#bit clk = 0xF83.0 // PORTD bit 0
#bit Data = 0xF83.1 // PORTD bit 1
int read_bit(void);
/* PROGRAM */
void main(void){
int i; //i,k
unsigned char d;
long int k;
init_ext_eeprom();
SET_TRIS_d(0b00000010);
while(1){
if (!input(pin_c7)){
output_high(pin_e2);
/* 100bit continuation is carried out. That '1' comes It waits. */
i = 0;
while(i<100){
if( read_bit() == 1) i++;
else i = 0;
}
/* '0' for 65 bits of continuation Detection*/
i = 0;
while(i<65){
if( read_bit() == 0) i++;
else i = 0;
}
/* The data for continuing 16 bits is disregarded. */
for( i=0; i<16; i++ ){
read_bit();
}
/* From here to an image data acquisition start */
for( k=0; k < 96*72*2; k++){ // for( k=0; k < 96*72*2; k++){
d = 0;
for (i=0; i<8; i++){
d <<= 1;
if(read_bit())
d |= 0x1;
}
write_ext_eeprom(k, d);
}
output_low(pin_e2);
}
else{
getc();
for( k=0; k < 96*72*2; k++){
putc(read_ext_eeprom(k));
}
}
}//while
} /* main */
int read_bit(){
int i, a;
clk=1;
a = data; /* 1bit read-out
clk=0;
if(a)
return 1;
else
return 0;
}
|
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Aug 05, 2004 5:46 am |
|
|
You wrote a program that works on the 16F877 but fails on the 18F452.... If this happens to me I always first look at the differences between those two situations.
Guest already pointed you to one of the differences in the hardware, the address of port D. You fixed this and it is still not working, the getc() fails....
Now a clever guy starts thinking: 'Hey, getc() uses the RS-232 ports. RS-232 is hardware..... Maybe I made the same mistake here too'.
Look it up in the manual and you will see that the PIC18F452 has the Tx and Rx on portC6 and C7. Change your #use rs232 accordingly. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Aug 05, 2004 5:57 am |
|
|
You RS232 speed should probably be 57600 instead of 56000. |
|
|
Onurr Guest
|
|
Posted: Thu Aug 05, 2004 6:39 am |
|
|
I changed But not working.. Ok I changed baud rate..
I know 18F have uart . You know 16f877 have a uart. but I don't use uart and code is working correctly..
you can use getc on 16f84 ..
now program send data some times..
I changed getc line
I added if(!input(pin_c7)
and C7 have Pull up I added one button to GND
program dont wait here. everytime sending data
Code: |
//#INCLUDE <16F877.h>
#include <18F452.h>
#use delay(clock=20000000)
#FUSES HS,NOWDT,NOPROTECT,NOLVP,noPUT, NOBROWNOUT
#use rs232(baud=19200, xmit=PIN_E0, rcv=PIN_E1)
#use fast_io(d)
int read_bit(void);
/* PROGRAM */
void main(void){
int i; //i,k
unsigned char d;
long int k;
SET_TRIS_d(0b00000010);
while(1){
getc();
output_high(pin_e2);
/* 100bit continuation is carried out. That '1' comes It waits. */
i = 0;
while(i<100){
if( read_bit() == 1) i++;
else i = 0;
}
/* '0' for 65 bits of continuation Detection*/
i = 0;
while(i<65){
if( read_bit() == 0) i++;
else i = 0;
}
/* The data for continuing 16 bits is disregarded. */
for( i=0; i<16; i++ ){
read_bit();
}
/* From here to an image data acquisition start */
for( k=0; k < 96*72*2; k++){ // for( k=0; k < 96*72*2; k++){
d = 0;
for (i=0; i<8; i++){
d <<= 1;
if(read_bit())
d |= 0x1;
}
/* The acquired data is transmitted to PC. */
// sci_outch(d);
putc(d);
}
output_low(pin_e2);
}//while
} /* main */
int read_bit(){
int i, a;
output_high(pin_d0)
a = input(pin_d1)/* 1bit read-out processing DOUT is read in a */
output_low(pin_d0);
if(a)
return 1;
else
return 0;
}
|
|
|
|
Guest
|
|
Posted: Thu Aug 05, 2004 6:54 am |
|
|
As ckielstra pointed out you have to check _all_ hardware aspects first.
For example I think port_e has alternate function (especially analog inputs). And port_e operates as analog port unless you explicitly initialize it to digital. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Aug 05, 2004 7:01 am |
|
|
Quote: | I know 18F have uart . You know 16f877 have a uart. but I don't use uart and code is working correctly.. | Sorry, my mistake. I only had a quick look at the 16F877 datasheet and mistook the RD and WR pins of the Parallel Slave Port for the UART transmit and receive pins. |
|
|
Onur
Joined: 11 Apr 2004 Posts: 11
|
|
Posted: Thu Aug 05, 2004 7:24 am |
|
|
This code sending to me Onur..
Code: |
#INCLUDE <18F452.h>
#use delay(clock=20000000)
#FUSES HS,NOWDT,NOPROTECT,NOLVP,noPUT, NOBROWNOUT
#use rs232(baud=9600, xmit=PIN_E0, rcv=PIN_E1)
void main(){
while(1){
puts("onur");
delay_ms(500);
}
}
|
And This code sending to me Onur but This program Must be wait on getc(); line. but dont wait.. some time sending 500ms delay some times wait 700ms delay
If I add SETUP_ADC_PORTS(NO_ANALOGS); this line. there is nothing to change
.. I cant understand it..... Please help me
Code: |
#INCLUDE <18F452.h>
#use delay(clock=20000000)
#FUSES HS,NOWDT,NOPROTECT,NOLVP,noPUT, NOBROWNOUT
#use rs232(baud=9600, xmit=PIN_E0, rcv=PIN_E1)
void main(){
while(1){
getc();
puts("onur");
delay_ms(500);
}
}
|
|
|
|
Onur
Joined: 11 Apr 2004 Posts: 11
|
|
Posted: Thu Aug 05, 2004 8:29 am |
|
|
Same problem on Kbhit code..
I tryed on 16f877 but dont work on 18F452
When I used 18F452 program always send me "onur"
I CAN'T UNDERSTAND IT SOMEONE HELP ME ....
THIS MAY BE BUG
Code: |
#INCLUDE <18F452.h>
//#INCLUDE <16F877.h>
#use delay(clock=20000000)
#FUSES HS,NOWDT,NOPROTECT,NOLVP,NOPUT, NOBROWNOUT,NOOSCSEN,NOSTVREN,NODEBUG,NOWRT,NOWRTD,NOWRTB,NOWRTC,NOCPD,NOCPB,NOEBTR,NOEBTRB
//#FUSES HS,NOWDT,NOPROTECT,NOLVP,noPUT, NOBROWNOUT
#use rs232(baud=9600, xmit=PIN_E0, rcv=PIN_E1)
void main(){
while(1){
if (kbhit()){
puts("onur");
delay_ms(500);
}
}
}
|
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Aug 05, 2004 8:50 am |
|
|
The software UART implementation of getc() waits for the detection of a start bit, apparently this start bit is detected by the software even when you don't send data. RS-232 voltage levels are inverted so I always get confused, but if I do remember it correclty, the level of a start bit is logic '0'.
So somehow there is a logic '0' on your pin_E1. What does your hardware interface to the PC look like? Are you using an RS-232 driver like the MAX232 ? Without an inverting driver like this you need to add the INVERT keyword to the #use rs232.
From the datasheet Quote: | PORTE pins are multiplexed with analog inputs. When selected as an analog input, these pins will read as �0�s. |
Quote: | On a Power-on Reset, these pins are configured as analog inputs. |
So you definately need the setup_adc_ports(NO_ANALOGs) or your getc will never wait. |
|
|
Guest
|
|
Posted: Thu Aug 05, 2004 9:36 am |
|
|
I tryed this one but dont work. I tested Kbhit. dont work....
when I using 16F877 its all right . It is working..
Code: |
void main(){
setup_adc_ports(NO_ANALOGs) ;
while(1){
getc();
puts("onur");
delay_ms(500);
}
}
|
|
|
|
Guest
|
|
Posted: Thu Aug 05, 2004 11:38 am |
|
|
I said that same thing.
I tested on 18F452 not working
but if you use 16f877 it will be work. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Aug 05, 2004 12:52 pm |
|
|
Compile the following and post you lst file.
Code: |
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=57600, xmit=PIN_E0, rcv=PIN_E1)
void main()
{
while(1)
{
getc();
puts("onur");
}
}
|
|
|
|
|
|
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
|