tsupuntu
Newbie
Offline
Posts: 18
Thank You
-Given: 0
-Receive: 1
|
|
« Reply #7 on: April 29, 2005, 07:14:37 19:14 » |
|
Yea!!! Now it work it change hex 16 bit to Dec and show to Sevensegment Now 4 digit but it improve to 10 digit =========================================
#include <16F628A.h> //#include #use delay(clock=4000000) #fuses NOWDT,XT, PUT, NOPROTECT, NOBROWNOUT, NOMCLR, LVP, NOCPD #byte VRCON = 0x9f #byte TRISB = 0x86 #byte TRISA = 0x85 #byte CMCON = 0x1f #byte INTCON = 0x0b #byte OPTION_REG = 0x81 #byte A = 0x05 #byte B = 0x06 //#bit inputalarm = B.1 //#bit sensor2= B.2 //#bit int0= B.0 //#bit sensor3 = B.3 #bit d0= A.0 #bit d1 = A.1 //#bit centrallock2= B.7 #bit d2 = A.2 #bit d3 = A.3 //#define lt 2 //#define cen1 1 //#define cen2 7 //#define sys 3 //#define al 0 //#define in 0 //#define sen1 2 //#define sen2 3 int32 i,buf,div1; int16 hde,key; int j,k,seg1,div2,seg0,seg2,seg3,seg4,seg5,seg6,seg7,seg8,seg9,m; void div(){ div1=buf/m; div2=buf-(m*div1); }
void hextodec(){ seg0=0; seg1=0; seg2=0; seg3=0; seg5=0; seg4=0; seg6=0; seg7=0; seg8=0; seg9=0; buf=i; m=0x0a; j=0; while(buf>0x00){
div(); buf=div1; if(j==0){seg0=div2;} if(j==1){seg1=div2;} if(j==2){seg2=div2;} if(j==3){seg3=div2;} if(j==4){seg4=div2;} if(j==5){seg5=div2;} if(j==6){seg6=div2;} if(j==7){seg7=div2;} if(j==8){seg8=div2;} if(j==9){seg9=div2;} j=j+1; } }
void segmentconv(){ // 0 1 2 3 4 5 6 7 8 9 a b c d e f byte const segmentdata[16] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; key=segmentdata[key]; } void main() { #ASM movlw 0x01 movlw 0x00 movwf TRISB movlw 0xf0 movwf TRISA clrf VRCON movlw 0x00 movwf INTCON bcf INTCON,1 movlw 0x07 movwf CMCON movlw 0xcd movwf OPTION_REG
#ENDASM //***+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //waitforstart(); i=0x00000000; start: //delay_ms(1000); hde=0x0000;
hextodec();
key=seg0; segmentconv(); output_b(key); bit_set(A,0); delay_us(12); bit_clear(A,0);
key=seg1; segmentconv(); output_b(key); bit_set(A,1); delay_us(12); bit_clear(A,1);
key=seg2; segmentconv();
output_b(key); bit_set(A,2); delay_us(12); bit_clear(A,2);
key=seg3; segmentconv();
output_b(key); bit_set(A,3); delay_us(12); bit_clear(A,3); //bit_set(A,1); //output_b(key); //bit_set(A,2); //output_b(key); //bit_set(A,3); //output_b(key); i=i+0x00000001; //if (i==0x0a){ //i=0; //} goto start;
}
|