PIC Vietnam

PIC Vietnam (http://www.picvietnam.com/forum/index.php)
-   Thực hành (http://www.picvietnam.com/forum/forumdisplay.php?f=20)
-   -   giúp mình với bài này sai chổ nào (http://www.picvietnam.com/forum/showthread.php?t=7088)

phieuduf9 30-09-2010 12:58 PM

giúp mình với bài này sai chổ nào
 
mình đang làm cái mạch máy tíh thường thôi chit cần nó cộng , trừ , nhân , chia đúng là đc đoạn code như thế này

Port D giao tiếp bàn phím HEX
Port C giao tiếp LCD
port E điều khiển LCD

nhưng làm hoài sữa hoài mà nó không chạy mô phỏng.
dịch được rồi ma mô phỏng không chạy
Pác nào pro sửa rồi post ngược lại dùm em.

yahoo mail : phieuduf9 (@yahoo.com)



#include "16F877A.h"
#include <math.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#byte portD=0x08
#byte portB=0x06
#byte portE=0x09
#define LCD portb
#define rs re0
#define rw re1
#define e re2
INT8 i,e,g,pheptoan;
int32 a,b,c,d,f,h,k,l;
int const so[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x3 9};
const unsigned char ketqua[]= {'#','K','E','T',' ','Q','U','A','=',' '};

void lenh(void)
{
output_low(pin_e0) ;
output_low(pin_e1);
output_high(pin_e2);
output_low(pin_e2);
delay_ms(6);
}

void du_lieu(void)
{
output_high(pin_e0);
output_low(pin_e1);
output_high(pin_e2);
output_low(pin_e2);
delay_ms(6);
}

void goi()
{
g=9;
while(ketqua[g]!='#')
{
output_b(ketqua[g]);
du_lieu();
delay_ms(100);
g--;
}
}

void main()
{ set_tris_e(0);output_e(0);
set_tris_b(0);output_b(0);
OUTPUT_B(0X38);
lenh();
portb=0x0e;
lenh();
output_b(0x82);
lenh();
delay_ms(100);
output_D(0b11111111);
delay_ms(10);
a=0;
b=0;
pheptoan=0;
e=0;i=0;
while(true)
{

//========================output_D(11111110)======== ====//
output_D(0b11111110);
DELAY_MS(10);

if( input(pin_D4)==0 ) //cho khi D4 xuong 0
{
portb=0x37; //ghi 7
du_lieu();
DELAY_MS(150);
if(pheptoan==1)
b=b*10+7;
if(pheptoan==0)
a=a*10+7;
}
if( input(PIN_D5)==0 ) //cho khi D5 xuong 0
{
portb=0x38; //ghi 8
du_lieu();
DELAY_MS(150);
if(pheptoan==1)
b=b*10+8;
if(pheptoan==0)
a=a*10+8;
}
if( input(PIN_D6)==0 ) //cho khi D6 xuong 0
{
portb=0x39; //ghi 9
du_lieu();
DELAY_MS(150);
if(pheptoan==1)
b=b*10+9;
if(pheptoan==0)
a=a*10+9;
}
if( input(PIN_D7)==0 ) //cho khi D7 xuong 0
{
portb='+'; // ghi +
du_lieu();
DELAY_MS(150);
pheptoan=1;
e=1;
}
//====================================output_D(11111 101)=============//
output_D(0b11111101);
DELAY_MS(10);
if( input(PIN_D4)==0 ) //cho khi D4 xuong 0
{
portb=0x34; //ghi 4
du_lieu();
DELAY_MS(150);
if(pheptoan==1)
b=b*10+4;
if(pheptoan==0)
a=a*10+4;
}
if( input(PIN_D5)==0 ) //cho khi D5 xuong 0
{
portb=0x35; //ghi 5
du_lieu();
DELAY_MS(150);
if(pheptoan==1)
b=b*10+5;
if(pheptoan==0)
a=a*10+5;
}
if( input(PIN_D6)==0 ) //cho khi D6 xuong 0
{
portb=0x36; //ghi 6
du_lieu();
DELAY_MS(150);
if(pheptoan==1)
b=b*10+6;
if(pheptoan==0)
a=a*10+6;
}
if( input(PIN_D7)==0 ) //cho khi D7 xuong 0
{
portb='-'; //ghi -
du_lieu();
DELAY_MS(150);
pheptoan=1;
e=2;
}
//================output_D(11111011)================ ====//
output_D(0b11111011);
DELAY_MS(10);
if( input(PIN_D4)==0 ) //cho khi D4 xuong 0
{
portb=0x31; //ghi 1
du_lieu();
DELAY_MS(150);
if(pheptoan==1)
b=b*10+1;
if(pheptoan==0)
a=a*10+1;
}
if( input(PIN_D5)==0 ) //cho khi D5 xuong 0
{
portb=0x32; //ghi 2
du_lieu();
DELAY_MS(150);
if(pheptoan==1)
b=b*10+2;
if(pheptoan==0)
a=a*10+2;
}
if( input(PIN_D6)==0 ) //cho khi D6 xuong 0
{
portb=0x33; //ghi 3
du_lieu();
DELAY_MS(150);
if(pheptoan==1)
b=b*10+3;
if(pheptoan==0)
a=a*10+3;
}
if( input(PIN_D7)==0 ) //cho khi D7 xuong 0
{
portb='x'; //ghi x
du_lieu();
DELAY_MS(150);
pheptoan=1;
e=3;
}
//*******************************output_D(0b11110111 )****************//
output_D(0b11110111);
DELAY_MS(10);
if( input(PIN_D4)==0 ) //cho khi D4 xuong 0
{
portb=0X01; //CLEAR
LENH();
delay_ms(1);
portb=0x82;
lenh();
delay_ms(1);
portb=0x06;
lenh();
delay_ms(1);
a=0;b=0;c=0;d=0;e=0;f=0;pheptoan=0;i=0;k=0;l=0;
}
if( input(PIN_D5)==0 ) //cho khi D5 xuong 0
{
portb=0x30; //ghi 0
du_lieu();
DELAY_MS(150);
if(pheptoan==1)
b=b*10+0;
if(pheptoan==0)
a=a*10+0;
}
if( input(PIN_D6)==0 ) //cho khi D6 xuong 0
{
if(e==1)
c=a+b;
if(e==2)
{
if(a<b)
{
c=b-a;
i=1;
}
else
{
c=a-b;
i=2;
}
}
if(e==3)
c=a*b;
if(e==4)
{
c=a/b;
k=a%b;
k=k*100000;
l=k/b;
}
if(e==0)
{c=a;}
portb=0xe7;
lenh();
delay_ms(100);
portb=0x05;
lenh();
delay_ms(100);
if(i!=1)
{
if(c!=0)
{
if(k!=0)
{
while(l!=0)
{
f=(l%10);
output_b(so[f]);
du_lieu();
delay_ms(1);
l=(l-f)/10;
}
portb='.'; //ghi .
du_lieu();
DELAY_MS(10);
}
while(c!=0)
{
f=(c%10);
output_b(so[f]);
du_lieu();
delay_ms(1);
c=(c-f)/10;
}

}
else
{
portb=so[0];
du_lieu();
}
}
else
{

while(c!=0)
{
h=(c%10);
output_b(so[h]);
du_lieu();
delay_ms(1);
c=(c-h)/10;
}
portb='-'; //ghi -
du_lieu();
DELAY_MS(10);
}
GOI();
delay_ms(1);

}
if( input(PIN_D7)==0 ) //cho khi D7 xuong 0
{portb='/'; //ghi /
du_lieu();
DELAY_MS(150);
pheptoan=1;
e=4;
}
}
}


Múi giờ GMT. Hiện tại là 05:28 AM.

Tên diễn đàn: vBulletin Version 3.8.11
Được sáng lập bởi Đoàn Hiệp.
Copyright © PIC Vietnam