|
|
View previous topic :: View next topic |
Author |
Message |
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
Kindly help with strange operation of 16F877A mcu |
Posted: Tue Aug 01, 2006 11:09 pm |
|
|
Hi,
Can anyone tell me what is wrong with this .TRE file, .LST file, the 16F877 mcu does not work at all, but if I remove some code it starts to work, but than I am using only 26% memory.
Also can anyone tell me if a function exceeds the segment size..
ÀÄCLG004Main-v2
ÃÄmain 1/105 Ram=0
³ ÃÄ??0??
³ ÃÄinitialise 0/45 Ram=0
³ ³ ÀÄinit_ext_eeprom (Inline) Ram=0
³ ÃÄload_settings 0/145 Ram=1
³ ³ ÃÄread_eeprom16byte 0/29 Ram=4
³ ³ ÃÄread_eeprom16byte 0/29 Ram=4
³ ³ ÀÄ@const10576 0/7 Ram=0
³ ÃÄcheck_mode 0/23 Ram=0
³ ÃÄcheck_selector 0/204 Ram=0
³ ³ ÀÄget_rotary_position (Inline) Ram=3
³ ³ ÀÄ@MUL88 0/39 Ram=2
³ ÃÄcheck_pushb 0/40 Ram=1
³ ³ ÀÄ@delay_ms1 0/23 Ram=1
³ ÃÄrelease_event 0/52 Ram=1
³ ³ ÃÄshow_cstep (Inline) Ram=1
³ ³ ³ ÀÄ@const10639 0/22 Ram=0
³ ³ ÀÄ@const10765 0/25 Ram=0
³ ÃÄpushb_event 0/151 Ram=1
³ ³ ÃÄselect_group (Inline) Ram=1
³ ³ ³ ÀÄ@const10654 0/19 Ram=0
³ ³ ÃÄ@const10739 0/19 Ram=0
³ ³ ÀÄshow_group 0/20 Ram=1
³ ³ ÀÄ@const10489 0/14 Ram=0
³ ÃÄzeroselect_event 0/54 Ram=1
³ ³ ÃÄshow_zero_err (Inline) Ram=1
³ ³ ³ ÀÄ@const10610 0/22 Ram=0
³ ³ ÀÄ@const10627 0/22 Ram=0
³ ÃÄselectorchange_event 0/29 Ram=1
³ ³ ÃÄ@const10713 0/26 Ram=0
³ ³ ÀÄshow_group 0/20 Ram=1
³ ³ ÀÄ@const10489 0/14 Ram=0
³ ÀÄusart_rcvr 0/155 Ram=0
³ ÃÄget_command (Inline) Ram=2
³ ³ ÀÄ@const10516 0/11 Ram=0
³ ÀÄprocess_command 0/365 Ram=2
³ ÃÄ@goto10561 0/24 Ram=0
³ ÃÄwrite_ext_eeprom (Inline) Ram=6
³ ³ ÃÄ@I2C_WRITE_1_59_60_4000000 0/73 Ram=1
³ ³ ÃÄ@I2C_WRITE_1_59_60_4000000 0/73 Ram=1
³ ³ ÃÄ@I2C_WRITE_1_59_60_4000000 0/73 Ram=1
³ ³ ÃÄ@I2C_WRITE_1_59_60_4000000 0/73 Ram=1
³ ³ ÃÄ@I2C_WRITE_1_59_60_4000000 0/73 Ram=1
³ ³ ÀÄ@I2C_WRITE_1_59_60_4000000 0/73 Ram=1
³ ÀÄread_ext_eeprom (Inline) Ram=5
³ ÃÄ@I2C_WRITE_1_59_60_4000000 0/73 Ram=1
³ ÃÄ@I2C_WRITE_1_59_60_4000000 0/73 Ram=1
³ ÃÄ@I2C_WRITE_1_59_60_4000000 0/73 Ram=1
³ ÃÄ@I2C_WRITE_1_59_60_4000000 0/73 Ram=1
³ ÀÄ@I2C_READ_1_59_60_4000000 0/70 Ram=3
ÃÄpc_usart_isr 0/10 Ram=0
ÀÄperipheral_usart_isr 0/28 Ram=2
ÃÄ@GETCH_3_ 0/54 Ram=1
ÃÄ@GETCH_4_ 0/54 Ram=1
ÀÄ@GETCH_2_ 0/54 Ram=1
The .LST file......
CCS PCM C Compiler, Version 3.228, 16542 02-Aug-06 16:25
Filename: CLG004Main-v2.LST
ROM used: 2093 words (26%)
Largest free fragment is 2048
RAM used: 55 (31%) at main() level
65 (37%) worst case
Stack: 5 worst case (3 in main + 2 for interrupts)
thanks
arunb |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Wed Aug 02, 2006 7:42 am |
|
|
..
Last edited by treitmey on Wed Aug 02, 2006 10:22 am; edited 1 time in total |
|
|
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
RE: |
Posted: Wed Aug 02, 2006 9:09 am |
|
|
Hi,
PCM: 3.228
MCU: 16F877A
It compiles alright, with no errors, but does not work , while in target board.
Well here is the code.
Code: |
#include <16F877A.h>
#priority RB,RDA
#use delay(clock=4000000)
#FUSES XT,NOWDT,PUT,NOPROTECT,NOCPD,BROWNOUT,NOLVP
#define EEPROM_SDA pin_c4
#define EEPROM_SCL pin_c3
#define EEPROM_SIZE 0x7FF8
#use rs232(baud=9600,xmit=pin_c6, rcv=pin_c7,parity=n,stream=PC)
#use rs232(baud=1200,xmit=pin_d5, rcv=pin_b5,parity=n,stream=DISPLAY)
#use rs232(baud=1200,xmit=pin_d7, rcv=pin_b3,parity=n,stream=RHSDRIVE)
#use rs232(baud=1200,xmit=pin_d6, rcv=pin_b4,parity=n,stream=LHSDRIVE)
#use i2c(master, sda=EEPROM_SDA, scl=EEPROM_SCL)
#define PLC1 pin_e0
#define PLC2 pin_e1
#define PLC3 pin_e2
#define R1P0 pin_a0
#define R1P1 pin_a1
#define R1P2 pin_a2
#define R1P3 pin_a3
#define R1P4 pin_a4
#define R1P5 pin_a5
#define R1P6 pin_c0
#define R2P0 pin_c1
#define R2P1 pin_c2
#define R2P2 pin_d0
#define R2P3 pin_d1
#define R2P4 pin_d2
#define R2P5 pin_d3
#define R2P6 pin_c5
#define PUSHB pin_b0
#define MODE pin_b1
#define VERSIONID "CLG004"
//Event Register Settings
//Bit 0 : Send command on controller start
//Bit 1 : Pushbutton Enable
//Bit 2 : Rotary Switch Change
//Bit 3 : Mode Selector Change
//Bit 4 : Checksum failed (for any peripheral)
//Bit 5 : Checksum Passed (for all peripherals)
//Bit 6 : PLC increment input receive
//Bit 7 : PLC decrement input receive
//Bit 8 : PLC reset input receive
//Bit 9 : Start motion process
//Bit 10 : End of motion
//Bit 11 :
//Bit 12 :
//Bit 13 :
//Bit 14 :
//Bit 15 :
//Bit 16 :
#define EVENTREG 0x04
#define WAITTIME 0x00
#define PERIPHERAL 0x02
#define MAXSTEPS 0xDF
#define RECIPE 0x09
#define TR0 0x0A
#define TR1 0x0B
#define TMPLOC 0x20
#define TMPDATA 0x24
int nDispRcv,nLHSRcv,nRHSRcv,nPeripheralRcv;
char cRcvData,nUSARTCmd,nLocation,cDevice;
int bPeripheralStatusFlg,bRcvFlg,bDisconnectFlg,bRPushbFlg,bPushbFlg,bGroupSelected;
int val,nPLC,nStep,nMaxSteps,nGroup,nSide;
int nSelector,nPrevMode,d0,d1,g0,g1,nPrevSelector;
int16 nTmp1,nEventReg,nTmp2;
int16 nWaitTime;
int r1,r2;
int bPushEvent,bReleaseEvent,bSelChangeEvent,bZSelectionEvent;
int bRunModeEvent;
int bProgramModeEvent,nMode,bShow,bWriteEEPROM,bReadEEPROM;
void init_ext_eeprom()
{
output_float(EEPROM_SCL);
output_float(EEPROM_SDA);
}
void write_ext_eeprom(long int address, BYTE data)
{
short int status;
i2c_start();
i2c_write(0xa0);
i2c_write(address>>8);
i2c_write(address);
i2c_write(data);
i2c_stop();
i2c_start();
status=i2c_write(0xa0);
while(status==1)
{
i2c_start();
status=i2c_write(0xa0);
}
}
BYTE read_ext_eeprom(long int address) {
BYTE data;
i2c_start();
i2c_write(0xa0);
i2c_write(address>>8);
i2c_write(address);
i2c_start();
i2c_write(0xa1);
data=i2c_read(0);
i2c_stop();
return(data);
}
void write_eeprom32byte(int nAddress,int32 nData)
{
write_eeprom(nAddress,make8(nData,3));
write_eeprom(nAddress+1,make8(nData,2));
write_eeprom(nAddress+2,make8(nData,1));
write_eeprom(nAddress+3,make8(nData,0));
}
int32 read_eeprom32byte(int nAddress)
{
int buffer1,buffer2,buffer3,buffer4;
buffer1=read_eeprom(nAddress);
buffer2=read_eeprom(nAddress+1);
buffer3=read_eeprom(nAddress+2);
buffer4=read_eeprom(nAddress+3);
return(make32(buffer1,buffer2,buffer3,buffer4));
}
void write_eeprom16byte(int nAddress,int16 nTData)
{
write_eeprom(nAddress,make8(nTData,1));
write_eeprom(nAddress+1,nTData);
}
int16 read_eeprom16byte(int nAddress)
{
int buffer1,buffer2;
buffer1=read_eeprom(nAddress);
buffer2=read_eeprom(nAddress+1);
return(make16(buffer1,buffer2));
}
void get_rotary_position1()
{
r1=0;
d0=0;
d1=0;
if (input(R1P0)==0)
{
r1++;
d0=0;
}
if (input(R1P1)==0)
{
r1++;
d0=1;
}
if (input(R1P2)==0)
{
r1++;
d0=2;
}
if (input(R1P3)==0)
{
r1++;
d0=3;
}
if (input(R1P4)==0)
{
r1++;
d0=4;
}
if (input(R1P5)==0)
{
r1++;
d0=5;
}
if (input(R1P6)==0)
{
r1++;
d0=6;
}
if (input(R2P0)==0)
{
r2++;
d1=0;
}
}
int get_rotary_position2()
{
if (input(R2P1)==0)
{
r2++;
d1=1;
}
if (input(R2P2)==0)
{
r2++;
d1=2;
}
if (input(R2P3)==0)
{
r2++;
d1=3;
}
if (input(R2P4)==0)
{
r2++;
d1=4;
}
if (input(R2P5)==0)
{
r2++;
d1=5;
}
if (input(R2P6)==0)
{
r2++;
d1=6;
}
//delay_ms(50);
return ((d1*0x0A)+d0);
}
void check_selector()
{
get_rotary_position1();
nSelector=get_rotary_position2();
nSelector=4;
if (nSelector!=nPrevSelector)
{
if (nSelector!=0)
{
nPrevSelector=nSelector;
bSelChangeEvent=1;
}
else
{
bZSelectionEvent=1;
}
}
}
void check_pushb()
{
if (input(PUSHB)==0)
{
if (bPushbFlg==0)
{
bPushbFlg=1;
bRPushbFlg=0;
delay_ms(20);
if (input(PUSHB)==0)
{
bPushEvent=1;
}
}
}
else
{
bPushbFlg=0;
if (bRPushbFlg==0)
{
bRPushbFlg=1;
bReleaseEvent=1;
}
}
}
void check_mode()
{
nMode=input(MODE);
if (nMode!=nPrevMode)
{
if (nMode==0)
bRunModeEvent=1;
else
bProgramModeEvent=1;
nPrevMode=nMode;
}
}
int16 get_step_data(int nTGroup ,int nTStep,int nSide)
{
int16 nAddrs;
int16 n;
int nCntr;
n=0xA6;
for(nCntr=1;nCntr<nTGroup;nCntr++)
n=n+0xA6;
n=n-0xA6;
switch (nSide)
{
case 'R': //Right Side
nAddrs=((2*nTStep))+n+2+80;
break;
case 'L': //Left Side
nAddrs=((2*nTStep))+n+2;
break;
}
return(make16(read_ext_eeprom(nAddrs),read_ext_eeprom(nAddrs+1)));
}
void save_step_data(int nTGroup ,int nSelStep,int16 nTDistance,int nDigSide)
{
int16 nAddrs;
int16 n;
int nCntr;
n=0xA6;
for(nCntr=1;nCntr<nTGroup;nCntr++)
n=n+0xA6;
n=n-0xA6;
switch (nDigSide)
{
case 'R': //Right Side
nAddrs=((2*nSelStep))+n+2+80;
break;
case 'L':
nAddrs=((2*nSelStep))+n+2;
break;
}
write_ext_eeprom(nAddrs,make8(nTDistance,1));
write_ext_eeprom(nAddrs+1,nTDistance);
}
void waitfordevicercv(char cStream)
{
int16 n;
int bEndWaitFlg;
bEndWaitFlg=0;
n=0;
do
{
if (cStream=='D')
{
if (bit_test(nPeripheralRcv,0)==1)
bEndWaitFlg=1;
}
if (cStream=='L')
{
if (bit_test(nPeripheralRcv,1)==1)
bEndWaitFlg=1;
}
if (cStream=='R')
{
if (bit_test(nPeripheralRcv,2)==1)
bEndWaitFlg=1;
}
delay_ms(1);
n++;
}while((n<nWaitTime)&&(bEndWaitFlg==0));
}
int sendcommand(int nCommand,int bWait,int bRcv,char cStream)
{
//nCommand = The command (in 8 bit format)
//bWait = bWait-1 : Wait for acknowledge
// bWait-0 : Ignore acknowledge
//bRcv = The received data or acknowledge command
//cStream = The peripheral to which command is to be sent
int h;
enable_interrupts(INT_RB);
enable_interrupts(GlOBAL);
h=0;
switch (cStream)
{
case 'D': //Display Module
if (bit_test(bPeripheralStatusFlg,2)==1)
{
bit_clear(nPeripheralRcv,0);
val=fputc(nCommand,DISPLAY);
h=1;
}
break;
case 'L': //Left Side Drive Unit
if (bit_test(bPeripheralStatusFlg,0)==1)
{
bit_clear(nPeripheralRcv,1);
val=fputc(nCommand,LHSDRIVE);
h=1;
}
break;
case 'R': //Right Side Drive Unit
if (bit_test(bPeripheralStatusFlg,1)==1)
{
bit_clear(nPeripheralRcv,2);
val=fputc(nCommand,RHSDRIVE);
h=1;
}
break;
}
if ((bWait==1)&&(h==1))
waitfordevicercv(cStream);
if ((bRcv==1)&&(h==1))
return (nDispRcv);
disable_interrupts(INT_RB);
}
int read_device_eeprom(int nTLocation,char cDeviceCode)
{
val=sendcommand('-',1,1,cDeviceCode);
val=sendcommand(nTLocation,1,1,cDeviceCode);
return (val);
}
void write_device_eeprom(int nTLocation,int nEData,char cDeviceCode)
{
val=sendcommand('+',1,1,cDeviceCode);
val=sendcommand(nTLocation,1,1,cDeviceCode);
val=sendcommand(nEData,1,1,cDeviceCode);
}
int16 read_device_eeprom16Byte(int nTLocation,char cDeviceCode)
{
int val2;
val=sendcommand('-',1,1,cDeviceCode);
val=sendcommand(nTLocation,1,1,cDeviceCode);
val=sendcommand('-',1,1,cDeviceCode);
val2=sendcommand(nTLocation+1,1,1,cDeviceCode);
return (make16(val,val2));
}
void write_device_eeprom16Byte(int nTLocation,int16 nData,char cDeviceCode)
{
val=sendcommand('+',1,1,cDeviceCode);
val=sendcommand(nTLocation,1,1,cDeviceCode);
val=sendcommand(make8(nData,1),1,1,cDeviceCode);
val=sendcommand('+',1,1,cDeviceCode);
val=sendcommand(nTLocation+1,1,1,cDeviceCode);
val=sendcommand(make8(nData,0),1,1,cDeviceCode);
}
void uploadgroup(int nTGroup,char cDeviceCode,int nSide)
{
int n1;
int16 n;
int nCntr;
n=0xA6;
for(nCntr=1;nCntr<nTGroup;nCntr++)
n=n+0xA6;
n=n-0xA6;
nMaxSteps=read_ext_eeprom(n+1);
if (cDeviceCode=='D')
{
write_device_eeprom(0xB0,nMaxSteps,'D');
for (n1=1;n1<=nMaxSteps;n1++)
{
nTmp1=get_step_data(nTGroup ,n1,'L');
write_device_eeprom16Byte((0x10+(n1*2)-2),nTmp1,'D');
write_device_eeprom16Byte((0x60+(n1*2)-2),nTmp1,'D');
if (n1==1)
sendcommand('r',1,1,cDeviceCode);
else
sendcommand('i',1,1,cDeviceCode);
}
}
else
{
for (n1=1;n1<=nMaxSteps;n1++)
{
nTmp1=get_step_data(nTGroup ,n1,nSide);
write_device_eeprom16Byte((n1*2)-2,nTmp1,cDeviceCode);
}
write_device_eeprom(0x90,nMaxSteps,'D');
}
}
void show_group()
{
/*
// val=fputc('D',DISPLAY);
// val=fputc(0x0F,DISPLAY);
val=fputc('N',DISPLAY);
val=fputc(g0,DISPLAY);
val=fputc(g1,DISPLAY);
val=fputc(15,DISPLAY);
val=fputc(15,DISPLAY);
val=fputc(0,DISPLAY);
val=fputc(78,DISPLAY);
val=fputc(79,DISPLAY);
val=fputc(5,DISPLAY);
val=fputc('R',DISPLAY);
bShowGroup=0;
*/
puts("SHOW RECIPE",PC);
}
r cDeviceCode,int nSide)
{
int n,nStart,nEnd;
nTmp2=0;
switch (cDeviceCode)
{
case 'L': //Left Driver
nStart=0;
nEnd=read_device_eeprom(0x90,'L');
break;
case 'R': //Right Driver
nStart=0;
nEnd=read_device_eeprom(0x90,'R');
break;
case 'D': //Display Unit
if (nSide=='L')
nStart=0x10;
else
nStart=0x60;
nEnd=read_device_eeprom(0xB0,'D');
break;
}
for (n=1;n<nEnd>=0xFFFF)||(nWaitTime==0))
nWaitTime=1000;
nEventReg=make16(read_eeprom(EVENTREG),read_eeprom(EVENTREG+1));
if (bit_test(nEventReg,0)==1)
puts("CS");
nGroup=read_eeprom(RECIPE);
if (nGroup==0)
{
write_eeprom(RECIPE,1);
write_eeprom(TR0,1);
write_eeprom(TR1,0);
}
}
#ZERO_RAM
void setup_ports()
{
setup_adc(ADC_OFF );
set_tris_a(0b11111111);
set_tris_b(0b11111111);
set_tris_d(0b00011111);
set_tris_c(0b10111111);
set_tris_e(0b11111111);
init_ext_eeprom();
output_float(pin_b4);
output_float(pin_d6);
output_float(pin_d5);
output_float(pin_b5);
output_float(pin_d7);
output_float(pin_b3);
}
void initialise()
{
nGroup=1;
g0=1;
g1=0;
disable_interrupts(INT_RB);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
}
void usart_rcvr()
{
bRcvFlg=0;
if (nUSARTCmd==0)
{
get_command1(cRcvData);
get_command2(cRcvData);
}
else
{
process_command1(cRcvData);
process_command2(cRcvData);
}
}
void show_zero_err()
{
if (bShow==0)
{
val=puts("ZERO RECIPE ERROR",PC);
bShow=1;
}
}
void zeroselect_event()
{
if (bShow==0)
{
show_zero_err();
bShow=1;
}
val=fputs("ZERO SELECT EVENT",PC);
bZSelectionEvent=0;
}
void show_cstep()
{
val=fputs("SHOW CURRENT STEP",PC);
}
void select_group()
{
nGroup=nSelector;
g0=d0;
g1=d1;
write_eeprom(RECIPE,nGroup);
write_eeprom(TR0,g0);
write_eeprom(TR1,g1);
bGroupSelected=1;
val=fputs("GROUP SELECTED",PC);
}
void run_mode_event()
{
val=fputs("RUN MODE EVENT",PC);
bShow=0;
if (nSelector!=0)
{
//Upload Data to peripherals here.
val=fputs("UPLOAD RECIPE",PC);
}
else
{
//Show Error
val=fputs("ZERO GROUP ERR",PC);
show_zero_err();
}
bRunModeEvent=0;
}
void program_mode_event()
{
val=fputs("PROGRAM MODE CHANGE EVENT",PC);
bShow=0;
bProgramModeEvent=0;
}
void selectorchange_event()
{
val=fputs("SELECTOR CHANGE EVENT",PC);
if (nMode==0)
show_group();
bShow=0;
bSelChangeEvent=0;
bGroupSelected=0;
}
void pushb_event()
{
if (nSelector!=0)
{
if (nMode==1)
{
if (bGroupSelected==0)
{
select_group();
}
else
{
val=fputs("INCREMENT STEP");
}
}
else
{
show_group();
bShow=0;
}
}
bPushEvent=0;
}
void release_event()
{
if (bShow==0)
{
if (nMode==0)
{
show_cstep();
}
bShow=1;
}
val=fputs("RELEASE BUTTON EVENT");
bReleaseEvent=0;
}
void main()
{
setup_ports();
initialise();
load_settings();
// waitfordevicercv('D');
bPeripheralStatusFlg=0x07;
do
{
check_mode();
check_selector();
check_pushb();
if (bReleaseEvent==1)
release_event();
if (bPushEvent==1)
pushb_event();
if (bZSelectionEvent==1)
zeroselect_event();
if (bSelChangeEvent==1)
selectorchange_event();
if (bRcvFlg==1)
usart_rcvr();
// if (bWriteEEPROM==1)
// {
// nTmp2=read_eeprom32byte(TMPLOC);
// nTmp1=read_eeprom16Byte(TMPDATA);
// write_ext_eeprom(nTmp2,nTmp1);
// val=fputc('A',PC);
// }
// if (bReadEEPROM==1)
// {
// nTmp2=read_eeprom32byte(TMPLOC);
// nTmp1=read_ext_eeprom(nTmp2);
// val=fputc(nTmp1,PC);
// }
}while(TRUE);
}
#int_rda
void pc_usart_isr()
{
cRcvData=getc();
bRcvFlg=1;
}
#int_rb
void peripheral_usart_isr()
{
int h;
h=input_b();
if (bit_test(h,3)==0)
{
nRHSRcv=fgetc(RHSDRIVE);
bit_set(nPeripheralRcv,2);
}
if (bit_test(h,4)==0)
{
nLHSRcv=fgetc(LHSDRIVE);
bit_set(nPeripheralRcv,1);
}
if (bit_test(h,5)==0)
{
nDispRcv=fgetc(DISPLAY);
bit_set(nPeripheralRcv,0);
}
}
|
I removed the check_rotary functions and it started to work, removing the usart_rcvr also worked...
thanks
arunb |
|
|
|
|
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
|