|
|
View previous topic :: View next topic |
Author |
Message |
louwi_138
Joined: 17 Nov 2012 Posts: 23
|
program chip error ; pic16f628A ; picc 4.110 PCB |
Posted: Tue Feb 12, 2013 12:31 am |
|
|
I tried to write this code after compilation in my pic but it didn't work !
I cheked my hardware by an other code it work fine. so it's software error.
Code: |
#include <16f628A.h>
#FUSES NOWDT
#FUSES INTRC_IO
#FUSES NOMCLR
#FUSES NOLVP
#use delay(clock=4000000)
#byte porta = 0xF05
#byte portb = 0xF06
#byte trisa = 0xF85
#byte trisb = 0xF86
// 0 1 2 3 4 5 6 7 8 9
//int8 t[10]={0b01111110,0b00001100,0b10110110,0b10011110,0b11001100,0b11011010,0b11111010,0b00001110,0b11111110,0b11011110};//tableuax de numéreaux codée
int8 t[10]={0b10000001,0b11110011,0b01001001,0b01100001,0b00110011,0b00100101,0b00000101,0b11110001,0b00000001,0b00100001};//tableuax de numéreaux codée
int8 taf[4]={0,0b01111110,0b01111110,0b01111110};//tableaux d'affichage
int8 i,n=3,digit1=0,digit2=0,digit3=0;
int32 tt;
void convertir(){//remplissage du tableux d'affichage
taf[1]=t[digit1];
taf[2]=t[digit2];
taf[3]=t[digit3];
}
#INT_TIMER0
void affichage()
{
switch (n){
case 1 : output_low(PIN_A0); //afficher digit3
output_high(PIN_A2);
n=2;
break;
case 2 : output_low(PIN_A2); //afficher digit2
output_high(PIN_A1);
n=3;
break;
case 3 : output_low(PIN_A1); //afficher digit1
output_high(PIN_A0);
n=1;
break;
}
portb=taf[n];
}
#INT_EXT
void arret(){
output_low(PIN_A7);
digit1=0;
digit2=0;
digit3=0;
convertir();
}
void main(){
porta=0;
output_low(PIN_A7);
portb=0;
//76543210
SET_TRIS_A(0b01111000);
//76543210
SET_TRIS_B(0b00000001);
//Timer
setup_timer_0(T0_INTERNAL|T0_DIV_256|T0_8_BIT);
ENABLE_INTERRUPTS(INT_TIMER0);
ENABLE_INTERRUPTS(GLOBAL);
//
convertir();
while(1){
while(input(PIN_A3)&&input(PIN_A4)&&input(PIN_A5)&&input(PIN_B0));
delay_ms(100);
if(!input(PIN_A3)){
if (digit1==9) digit1=0;
else digit1++;
delay_ms(400);
}
if(!input(PIN_A4)){
if (digit2==9) digit3=0;
else digit2++;
delay_ms(400);
}
if(!input(PIN_A5)){
if (digit3==9) digit3=0;
else digit3++;
delay_ms(400);
}
tt=digit1*10+digit2*100+digit3*1000;
convertir();
if(!input(PIN_B0)){
enable_INTERRUPTS(INT_EXT_L2H);
output_high(PIN_A7);
delay_ms(tt);
output_low(PIN_A7);
disable_INTERRUPTS(INT_EXT_L2H);
digit1=0;
digit2=0;
digit3=0;
convertir();
delay_ms(5000);
}
}
}
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Tue Feb 12, 2013 1:49 am |
|
|
Different PIC.....
Without looking any further, what are the register addresses for PORTA, B etc., on the PIC16. Not the same as on a PIC18 (which the code is written for.....).
Take advantage of the compiler's ability to do this for you:
Code: |
#byte porta = getenv("SFR:PORTA")
#byte portb = getenv("SFR:PORTB")
#byte trisa = getenv("SFR:TRISA")
#byte trisb = getenv("SFR:TRISB")
|
However it is also much safer and easier to not use the direct port defines, but use the compiler's own functions. output_b will send a byte to portB. set_tris_b will set the tris etc. etc.. Using register defines is a sign of somebody not really 'getting their head round' using CCS.
Best Wishes |
|
|
louwi_138
Joined: 17 Nov 2012 Posts: 23
|
|
Posted: Wed Feb 13, 2013 3:39 am |
|
|
Ttelmah wrote: | Different PIC.....
Without looking any further, what are the register addresses for PORTA, B etc., on the PIC16. Not the same as on a PIC18 (which the code is written for.....).
Take advantage of the compiler's ability to do this for you:
Code: |
#byte porta = getenv("SFR:PORTA")
#byte portb = getenv("SFR:PORTB")
#byte trisa = getenv("SFR:TRISA")
#byte trisb = getenv("SFR:TRISB")
|
However it is also much safer and easier to not use the direct port defines, but use the compiler's own functions. output_b will send a byte to portB. set_tris_b will set the tris etc. etc.. Using register defines is a sign of somebody not really 'getting their head round' using CCS.
Best Wishes |
I tried that and it's the same problem.
I use portb) and not the function because I'm using the pin PB0 as input. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Wed Feb 13, 2013 5:03 am |
|
|
There are a lot of problems in the code. First the port defines already mentioned.
Then you have a routine used both inside an ISR, and outside. This will mean that interrupts are disabled around that routine in the external code.
Then you are not disabling the comparator. This normally defaults to 'on'.
Then similarly you are not configuring the ADC - on some chips the pins default to analog mode.
Then types. What is the maximum value that delay_ms can accept as a variable?. int32?. Why use an int32, if it can't accept it?.
_Think_.
Learn to debug. Start by just doing _one_ thing. Say toggling a pin. Once you have this happening, and at the expected frequency, you know that your clock settings are working an your I/O.
Then step forwards one step at a time. See if you can stop/start the toggle with an input pin. Then try your combination of pins for the same function. Prove what parts work, and what parts don't.
"It doesn't work" tells nobody anything - including yourself.....
Best Wishes |
|
|
|
|
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
|