Newsgroup: it.hobby.elettronica.digitale
Titolo: scusate.....

 "65"
72:                //
-------------------------------------------------------------------------------------
73:                void char2dec(char value, char * string) {
74:
75:                	int2dec((int)(value), string);
  03C7    1283     BCF 0x3, 0x5
  03C8    1303     BCF 0x3, 0x6
  03C9    00A0     MOVWF 0x20
  03CA    0820     MOVF 0x20, W
  03CB    00AC     MOVWF 0x2c
  03CC    01AD     CLRF 0x2d
  03CD    0820     MOVF 0x20, W
  03CE    00AE     MOVWF 0x2e
  03CF    120A     BCF 0xa, 0x4
  03D0    118A     BCF 0xa, 0x3
  03D1    259D     CALL 0x59d
  03D2    120A     BCF 0xa, 0x4
  03D3    118A     BCF 0xa, 0x3
76:                }
  03D4    1303     BCF 0x3, 0x6
77:
78:
79:
80:                //
-------------------------------------------------------------------------------------
81:                // Converte un carattere in stringa ASCII
esadecimale. Es. 'A' --> "41"
82:                // Equivale a convertire un byte (a valore
esadecimale) in stringa. Es. A --> "41"
83:                //
-------------------------------------------------------------------------------------
84:                void char2hex(char value, char * string) {
85:
86:                	string[0] = value >> 4;
  048F    1283     BCF 0x3, 0x5
  0490    1303     BCF 0x3, 0x6
  0491    00A0     MOVWF 0x20
  0492    0820     MOVF 0x20, W
  0493    0084     MOVWF 0x4
  0494    1383     BCF 0x3, 0x7
  0495    0E20     SWAPF 0x20, W
  0496    390F     ANDLW 0xf
  0497    0080     MOVWF 0
87:                	if (string[0] < 10) string[0] += 48;        //
Cifra numerica, partire da 48
  0498    0820     MOVF 0x20, W
  0499    0084     MOVWF 0x4
  049A    1383     BCF 0x3, 0x7
  049B    300A     MOVLW 0xa
  049C    0200     SUBWF 0, W
  049D    1803     BTFSC 0x3, 0
  049E    2CA0     GOTO 0x4a0
  049F    2CA1     GOTO 0x4a1
  04A0    2CA7     GOTO 0x4a7
  04A1    0820     MOVF 0x20, W
  04A2    0084     MOVWF 0x4
  04A3    1383     BCF 0x3, 0x7
  04A4    3030     MOVLW 0x30
  04A5    0780     ADDWF 0, F
  04A6    2CAE     GOTO 0x4ae
88:                	else string[0] += 55;                       //
Cifra letterale, partire da 55
  04A7    1283     BCF 0x3, 0x5
  04A8    1303     BCF 0x3, 0x6
  04A9    0820     MOVF 0x20, W
  04AA    0084     MOVWF 0x4
  04AB    1383     BCF 0x3, 0x7
  04AC    3037     MOVLW 0x37
  04AD    0780     ADDWF 0, F
89:
90:                	string[1] = value & 0x0F;
  04AE    1283     BCF 0x3, 0x5
  04AF    1303     BCF 0x3, 0x6
  04B0    0A20     INCF 0x20, W
  04B1    0084     MOVWF 0x4
  04B2    1383     BCF 0x3, 0x7
  04B3    0820     MOVF 0x20, W
  04B4    390F     ANDLW 0xf
  04B5    0080     MOVWF 0
91:                	if (string[1] < 10) string[1] += 48;
  04B6    0A20     INCF 0x20, W
  04B7    0084     MOVWF 0x4
  04B8    1383     BCF 0x3, 0x7
  04B9    300A     MOVLW 0xa
  04BA    0200     SUBWF 0, W
  04BB    1803     BTFSC 0x3, 0
  04BC    2CBE     GOTO 0x4be
  04BD    2CBF     GOTO 0x4bf
  04BE    2CC5     GOTO 0x4c5
  04BF    0A20     INCF 0x20, W
  04C0    0084     MOVWF 0x4
  04C1    1383     BCF 0x3, 0x7
  04C2    3030     MOVLW 0x30
  04C3    0780     ADDWF 0, F
  04C4    2CCC     GOTO 0x4cc
92:                	else string[1] += 55;
  04C5    1283     BCF 0x3, 0x5
  04C6    1303     BCF 0x3, 0x6
  04C7    0A20     INCF 0x20, W
  04C8    0084     MOVWF 0x4
  04C9    1383     BCF 0x3, 0x7
  04CA    3037     MOVLW 0x37
  04CB    0780     ADDWF 0, F
93:
94:                    string[2] = '\0';							// Imposta termine
stringa
  04CC    1283     BCF 0x3, 0x5
  04CD    1303     BCF 0x3, 0x6
  04CE    0820     MOVF 0x20, W
  04CF    3E02     ADDLW 0x2
  04D0    0084     MOVWF 0x4
  04D1    1383     BCF 0x3, 0x7
  04D2    0180     CLRF 0
95:                }
  04D3    1303     BCF 0x3, 0x6
---  C:\Documents and Settings\Administrator\Desktop\Routine\delay.c
----------------------------
1:                 /*
2:                  *	Delay functions
3:                  *	See delay.h for details
4:                  *
5:                  *	Make sure this code is compiled with full
optimization!!!
6:                  */
7:
8:                 #include	"delay.h"
9:
10:                void
11:                DelayMs(unsigned char cnt)
12:                {
13:                #if	XTAL_FREQ <= 2MHZ
14:                	do {
15:                		DelayUs(996);
16:                	} while(--cnt);
17:                #endif
18:
19:                #if    XTAL_FREQ > 2MHZ
20:                	unsigned char	i;
  0424    1283     BCF 0x3, 0x5
  0425    1303     BCF 0x3, 0x6
  0426    00A1     MOVWF 0x21
21:                	do {
22:                		i = 4;
  0427    3004     MOVLW 0x4
  0428    1283     BCF 0x3, 0x5
  0429    1303     BCF 0x3, 0x6
  042A    00A0     MOVWF 0x20
23:                		do {
24:                			DelayUs(250);
  042B    3053     MOVLW 0x53
  042C    1283     BCF 0x3, 0x5
  042D    1303     BCF 0x3, 0x6
  042E    00A2     MOVWF 0x22
  042F    2C31     GOTO 0x431
  0430    2C31     GOTO 0x431
  0431    1283     BCF 0x3, 0x5
  0432    1303     BCF 0x3, 0x6
  0433    0BA2     DECFSZ 0x22, F
  0434    2C36     GOTO 0x436
  0435    2C37     GOTO 0x437
  0436    2C30     GOTO 0x430
25:                		} while(--i);
  0437    1283     BCF 0x3, 0x5
  0438    1303     BCF 0x3, 0x6
  0439    0BA0     DECFSZ 0x20, F
  043A    2C3C     GOTO 0x43c
  043B    2C3D     GOTO 0x43d
  043C    2C2B     GOTO 0x42b
26:                	} while(--cnt);
  043D    1283     BCF 0x3, 0x5
  043E    1303     BCF 0x3, 0x6
  043F    0BA1     DECFSZ 0x21, F
  0440    2C42     GOTO 0x442
  0441    2C43     GOTO 0x443
  0442    2C27     GOTO 0x427
27:                #endif
28:                }
  0443    1303     BCF 0x3, 0x6
---  C:\Documents and Settings\Administrator\Desktop\Routine\uart.c
-----------------------------
1:                 //
---------------------------------------------------------------------------------------
2:                 // File:			Uart.c																 -
3:                 // Autore:			Nicola Sellitto
snic...@yahoo.it
								 -
4:                 // Versione:		0.2																	 -
5:                 // Data:			24 Maggio 2003														 -
6:                 // Descrizione:		Gestione seriale hardware dei
16F87x     							 -
7:                 // Verifiche:		Prove eseguite su 16F876
20Mhz          							 -
8:                 // Note:			Relazione tra Frequenza e Baud rate
								 -
9:                 //	BRGH=1, Fosc=4MHz     BRGH=1, Fosc=8MHz
BRGH=1, Fosc=16MHz     BRGH=1, Fosc=20MHz-
10:                //	-----------------     -----------------
------------------     -------------------
11:                //	Baud		SPBRG     Baud		  SPBRG     Baud
SPBRG     Baud		 SPBRG   -
12:                //	  1200		207.3       1200	  415.7
9600       103.2       9600    129.2   -
13:                //	  2400		103.2       2400	  207.3      19200
51.1      19200     64.1   -
14:                //	  4800		 51.1       4800	  103.2
38400        25.0      38400     31.5   -
15:                //	  9600		 25.0       9600	   51.1
57600        16.3      57600     20.7   -
16:                //	 19200		 12.0      19200	   25.0
115200         7.7     115200      9.8   -
17:                //	 38400		  5.5      38400	   12.0
230400         3.3     230400      4.4   -
18:                //	 57600		  3.3      57600
7.7                            460800      1.7   -
19:                //	115200	      1.2     115200
3.3                                              -
20:                //
---------------------------------------------------------------------------------------
21:
22:                #include	<pic.h>
23:                #include 	"delay.h"
24:                #include 	"uart.h"
25:
26:
27:                //
---------------------------------------------------------------------------------------
28:                // Inizializzazione Uart
29:                //
---------------------------------------------------------------------------------------
30:                unsigned char UartInit(const unsigned char clock,
const unsigned long baudrate, const unsigned char config) {
31:
32:                	SYNC = UART_ASYNCHRONOUS;				// Imposta modalità
asincrona
  04D6    1683     BSF 0x3, 0x5
  04D7    1303     BCF 0x3, 0x6
  04D8    1218     BCF 0x18, 0x4
33:                	BRGH = UART_BAUDRATE_HIGH;				// Imposta baud rate
per high speed
  04D9    1518     BSF 0x18, 0x2
34:                	SPBRG = UartGetBRG(clock, baudrate,
UART_BAUDRATE_HIGH);
  04DA    1283     BCF 0x3, 0x5
  04DB    00B1     MOVWF 0x31
  04DC    082C     MOVF 0x2c, W
  04DD    00B2     MOVWF 0x32
  04DE    082D     MOVF 0x2d, W
  04DF    00B3     MOVWF 0x33
  04E0    082E     MOVF 0x2e, W
  04E1    00B4     MOVWF 0x34
  04E2    082F     MOVF 0x2f, W
  04E3    00B5     MOVWF 0x35
  04E4    01B6     CLRF 0x36
  04E5    0AB6     INCF 0x36, F
  04E6    0831     MOVF 0x31, W
  04E7    120A     BCF 0xa, 0x4
  04E8    118A     BCF 0xa, 0x3
  04E9    2626     CALL 0x626
  04EA    120A     BCF 0xa, 0x4
  04EB    118A     BCF 0xa, 0x3
  04EC    1683     BSF 0x3, 0x5
  04ED    0099     MOVWF 0x19
35:
36:                	TXIE = UART_TX_INTERRUPT_DISABLE;		// Disabilita
interrupts in Trasmissione
  04EE    120C     BCF 0xc, 0x4
37:                	RCIE = UART_RX_INTERRUPT_DISABLE;		// Disabilita
interrupts in Ricezione
  04EF    128C     BCF 0xc, 0x5
38:                	switch (config) {
  04F0    2D10     GOTO 0x510
  0510    1283     BCF 0x3, 0x5
  0511    1303     BCF 0x3, 0x6
  0512    0830     MOVF 0x30, W
  0513    3A01     XORLW 0x1
  0514    1903     BTFSC 0x3, 0x2
  0515    2CFE     GOTO 0x4fe
  0516    3A02     XORLW 0x2
  0517    1903     BTFSC 0x3, 0x2
  0518    2D04     GOTO 0x504
  0519    3A07     XORLW 0x7
  051A    1903     BTFSC 0x3, 0x2
  051B    2CF1     GOTO 0x4f1
  051C    3A01     XORLW 0x1
  051D    1903     BTFSC 0x3, 0x2
  051E    2CF7     GOTO 0x4f7
  051F    2D0A     GOTO 0x50a
39:                       case UART_CFG_BITSTOP_1 :
40:                		 	TX9 = UART_BITDATA_8;			// 8-bit Trasmissione
  04F1    1683     BSF 0x3, 0x5
  04F2    1303     BCF 0x3, 0x6
  04F3    1318     BCF 0x18, 0x6
41:                			RX9 = UART_BITDATA_8;			// 8-bit Ricezione
  04F4    1283     BCF 0x3, 0x5
  04F5    1318     BCF 0x18, 0x6
42:                        	break;
  04F6    2D20     GOTO 0x520
43:                       case UART_CFG_BITSTOP_2 :
44:                			TX9D = 1;						// 9-bit sempre ad 1
  04F7    1683     BSF 0x3, 0x5
  04F8    1303     BCF 0x3, 0x6
  04F9    1418     BSF 0x18, 0
45:                		 	TX9 = UART_BITDATA_9;			// 9-bit Trasmissione
  04FA    1718     BSF 0x18, 0x6
46:                			RX9 = UART_BITDATA_9;			// 9-bit Ricezione
  04FB    1283     BCF 0x3, 0x5
  04FC    1718     BSF 0x18, 0x6
47:                        	break;
  04FD    2D20     GOTO 0x520
48:                       case UART_CFG_PARITY_ODD :
49:                		 	TX9 = UART_BITDATA_9;			// 9-bit Trasmissione
  04FE    1683     BSF 0x3, 0x5
  04FF    1303     BCF 0x3, 0x6
  0500    1718     BSF 0x18, 0x6
50:                			RX9 = UART_BITDATA_9;			// 9-bit Ricezione
  0501    1283     BCF 0x3, 0x5
  0502    1718     BSF 0x18, 0x6
51:                        	break;
  0503    2D20     GOTO 0x520
52:                        case UART_CFG_PARITY_EVEN :
53:                		 	TX9 = UART_BITDATA_9;			// 9-bit Trasmissione
  0504    1683     BSF 0x3, 0x5
  0505    1303     BCF 0x3, 0x6
  0506    1718     BSF 0x18, 0x6
54:                			RX9 = UART_BITDATA_9;			// 9-bit Ricezione
  0507    1283     BCF 0x3, 0x5
  0508    1718     BSF 0x18, 0x6
55:                        	break;
  0509    2D20     GOTO 0x520
56:                        default:
57:                		 	TX9 = UART_BITDATA_8;			// 8-bit Trasmissione
  050A    1683     BSF 0x3, 0x5
  050B    1303     BCF 0x3, 0x6
  050C    1318     BCF 0x18, 0x6
58:                			RX9 = UART_BITDATA_8;			// 8-bit Ricezione
  050D    1283     BCF 0x3, 0x5
  050E    1318     BCF 0x18, 0x6
59:                	}
  050F    2D20     GOTO 0x520
60:
61:                	SPEN = UART_ENABLE;						// Abilita pin porta
seriale
  0520    1283     BCF 0x3, 0x5
  0521    1303     BCF 0x3, 0x6
  0522    1798     BSF 0x18, 0x7
62:                	CREN = UART_RX_ENABLE;					// Abilita Ricezione
  0523    1618     BSF 0x18, 0x4
63:                	TXEN = UART_TX_DISABLE;					// Reset Trasmissione
  0524    1683     BSF 0x3, 0x5
  0525    1298     BCF 0x18, 0x5
64:                	TXEN = UART_TX_ENABLE;					// Abilita Trasmissione
  0526    1698     BSF 0x18, 0x5
65:                	return SPBRG;
  0527    0819     MOVF 0x19, W
  0528    2D29     GOTO 0x529
66:                }
  0529    1303     BCF 0x3, 0x6
67:
68:
69:                //
---------------------------------------------------------------------------------------
70:                // Azzera la presenzadi errori
71:                //
---------------------------------------------------------------------------------------
72:                void UartClearErrors(void) {
73:                unsigned char dummy;
74:
75:                	if (OERR) {
  03EA    1283     BCF 0x3, 0x5
  03EB    1303     BCF 0x3, 0x6
  03EC    1C98     BTFSS 0x18, 0x1
  03ED    2BEF     GOTO 0x3ef
  03EE    2BF0     GOTO 0x3f0
  03EF    2BF6     GOTO 0x3f6
76:                		TXEN = UART_TX_DISABLE;
  03F0    1683     BSF 0x3, 0x5
  03F1    1298     BCF 0x18, 0x5
77:                		TXEN = UART_TX_ENABLE;
  03F2    1698     BSF 0x18, 0x5
78:                		CREN = UART_RX_DISABLE;
  03F3    1283     BCF 0x3, 0x5
  03F4    1218     BCF 0x18, 0x4
79:                		CREN = UART_RX_ENABLE;
  03F5    1618     BSF 0x18, 0x4
80:                	}
81:                	if (FERR) {
  03F6    1283     BCF 0x3, 0x5
  03F7    1303     BCF 0x3, 0x6
  03F8    1D18     BTFSS 0x18, 0x2
  03F9    2BFB     GOTO 0x3fb
  03FA    2BFC     GOTO 0x3fc
  03FB    2C01     GOTO 0x401
82:                		dummy = RCREG;
  03FC    081A     MOVF 0x1a, W
  03FD    00B0     MOVWF 0x30
83:                		TXEN = UART_TX_DISABLE;
  03FE    1683     BSF 0x3, 0x5
  03FF    1298     BCF 0x18, 0x5
84:                		TXEN = UART_TX_ENABLE;
  0400    1698     BSF 0x18, 0x5
85:                	}
86:                }
  0401    1303     BCF 0x3, 0x6
87:
88:
89:
90:                //
---------------------------------------------------------------------------------------
91:                // Scrive un singolo carattere sulla porta seriale
92:                //
---------------------------------------------------------------------------------------
93:                void UartPutch(unsigned char c) {
94:
95:                	while(!TXIF) {							// Verifica se il registro è
vuoto
  0404    1283     BCF 0x3, 0x5
  0405    1303     BCF 0x3, 0x6
  0406    00AE     MOVWF 0x2e
  0407    2C0D     GOTO 0x40d
  040D    1283     BCF 0x3, 0x5
  040E    1303     BCF 0x3, 0x6
  040F    1E0C     BTFSS 0xc, 0x4
  0410    2C12     GOTO 0x412
  0411    2C13     GOTO 0x413
  0412    2C08     GOTO 0x408
96:                		UartClearErrors();
  0408    120A     BCF 0xa, 0x4
  0409    118A     BCF 0xa, 0x3
  040A    23EA     CALL 0x3ea
  040B    120A     BCF 0xa, 0x4
  040C    118A     BCF 0xa, 0x3
97:                //		CLRWDT();
98:                	}
99:                	TXREG=c;
  0413    1283     BCF 0x3, 0x5
  0414    1303     BCF 0x3, 0x6
  0415    082E     MOVF 0x2e, W
  0416    0099     MOVWF 0x19
100:               	DelayUs(60);
  0417    3015     MOVLW 0x15
  0418    00AF     MOVWF 0x2f
  0419    2C1B     GOTO 0x41b
  041A    2C1B     GOTO 0x41b
  041B    1283     BCF 0x3, 0x5
  041C    1303     BCF 0x3, 0x6
  041D    0BAF     DECFSZ 0x2f, F
  041E    2C20     GOTO 0x420
  041F    2C21     GOTO 0x421
  0420    2C1A     GOTO 0x41a
101:               }
  0421    1303     BCF 0x3, 0x6
102:
103:
104:               //
---------------------------------------------------------------------------------------
105:               // Scrive una stringa di caratteri sulla porta
seriale
106:               //
---------------------------------------------------------------------------------------
107:               void UartPuts(const char *str) {
108:
109:               	while((*str)!=0) {
  046A    2C7D     GOTO 0x47d
  047D    1283     BCF 0x3, 0x5
  047E    1303     BCF 0x3, 0x6
  047F    082D     MOVF 0x2d, W
  0480    00D0     MOVWF 0x50
  0481    082C     MOVF 0x2c, W
  0482    120A     BCF 0xa, 0x4
  0483    118A     BCF 0xa, 0x3
  0484    200F     CALL 0xf
  0485    120A     BCF 0xa, 0x4
  0486    118A     BCF 0xa, 0x3
  0487    3800     IORLW 0
  0488    1D03     BTFSS 0x3, 0x2
  0489    2C8B     GOTO 0x48b
  048A    2C8C     GOTO 0x48c
  048B    2C6B     GOTO 0x46b
110:               		UartPutch(*str);
  046B    1283     BCF 0x3, 0x5
  046C    1303     BCF 0x3, 0x6
  046D    082D     MOVF 0x2d, W
  046E    00D0     MOVWF 0x50
  046F    082C     MOVF 0x2c, W
  0470    120A     BCF 0xa, 0x4
  0471    118A     BCF 0xa, 0x3
  0472    200F     CALL 0xf
  0473    120A     BCF 0xa, 0x4
  0474    118A     BCF 0xa, 0x3
  0475    120A     BCF 0xa, 0x4
  0476    118A     BCF 0xa, 0x3
  0477    2404     CALL 0x404
  0478    120A     BCF 0xa, 0x4
  0479    118A     BCF 0xa, 0x3
111:               //    	if (*str==13) putch(10);   ????
112:               //    	if (*str==10) putch(13);   ???
113:               		str++;
  047A    0AAC     INCF 0x2c, F
  047B    1903     BTFSC 0x3, 0x2
  047C    0AAD     INCF 0x2d, F
114:               	}
115:               }
  048C    1303     BCF 0x3, 0x6
116:
117:
118:
119:               //
---------------------------------------------------------------------------------------
120:               // Legge un carattere dalla seriale senza limiti di
Timeout
121:               //
---------------------------------------------------------------------------------------
122:               unsigned char UartGetch(void) {
123:
124:               	while(!RCIF) {
  03D7    2BDD     GOTO 0x3dd
  03DD    1283     BCF 0x3, 0x5
  03DE    1303     BCF 0x3, 0x6
  03DF    1E8C     BTFSS 0xc, 0x5
  03E0    2BE2     GOTO 0x3e2
  03E1    2BE3     GOTO 0x3e3
  03E2    2BD8     GOTO 0x3d8
125:               //		CLRWDT();
126:               		UartClearErrors();
  03D8    120A     BCF 0xa, 0x4
  03D9    118A     BCF 0xa, 0x3
  03DA    23EA     CALL 0x3ea
  03DB    120A     BCF 0xa, 0x4
  03DC    118A     BCF 0xa, 0x3
127:               	}
128:               	return RCREG;
  03E3    1283     BCF 0x3, 0x5
  03E4    1303     BCF 0x3, 0x6
  03E5    081A     MOVF 0x1a, W
  03E6    2BE7     GOTO 0x3e7
129:               }
  03E7    1303     BCF 0x3, 0x6
130:
131:
132:               //
---------------------------------------------------------------------------------------
133:               // Legge un carattere dalla seriale considerando un
Timeout
134:               //
---------------------------------------------------------------------------------------
135:               unsigned char UartGetchTimeout(void) {
136:               unsigned char i;
137:               unsigned int timeout_int;
138:
139:               	// retrieve one byte with a timeout
140:               //	for (i=2; i!= 0;i--) {
141:               //		timeout_int = timeout_int_us(240000);
142:
143:               		//only check the msb of the int for being 0, it
saves space, see always.h for macro
144:               //		while (hibyte(timeout_int)!=0) {
145:               //			CLRWDT();
146:               //			timeout_int--;
147:               //			if (RCIF) return RCREG;
148:               //		}
149:               //	}
150:               	return 0;
  03C2    3000     MOVLW 0
  03C3    2BC4     GOTO 0x3c4
151:               }
  03C4    1303     BCF 0x3, 0x6
152:
153:
154:               //
---------------------------------------------------------------------------------------
155:               // Ritorna il valore del registro SPBRG come
arrotondamento all'intero più vicino
156:               // SPBRG = (FOSC / (k*BR)) - 1, con k=16 per High
Speed=1 e k=64 per High Speed=0
157:               // Il valore di clock è espresso in Mhz
158:               //
---------------------------------------------------------------------------------------
159:               unsigned char UartGetBRG(const unsigned char clock,
const unsigned long baudrate, const unsigned char speed) {
160:               unsigned char round;
161:               unsigned long rem;
162:               unsigned long fosc;
163:               unsigned long div;
164:               unsigned long quot;
165:               unsigned long two;
166:               unsigned char brg;
167:               unsigned char k;
168:
169:               	if (speed) k = 16;						// Imposta la costante ...
  0626    1283     BCF 0x3, 0x5
  0627    1303     BCF 0x3, 0x6
  0628    00CE     MOVWF 0x4e
  0629    08B6     MOVF 0x36, F
  062A    1903     BTFSC 0x3, 0x2
  062B    2E2D     GOTO 0x62d
  062C    2E2E     GOTO 0x62e
  062D    2E31     GOTO 0x631
  062E    3010     MOVLW 0x10
  062F    00CD     MOVWF 0x4d
  0630    2E35     GOTO 0x635
170:               	else k = 64;							// moltiplicativa
  0631    3040     MOVLW 0x40
  0632    1283     BCF 0x3, 0x5
  0633    1303     BCF 0x3, 0x6
  0634    00CD     MOVWF 0x4d
171:               	two = 2;
  0635    3002     MOVLW 0x2
  0636    1283     BCF 0x3, 0x5
  0637    1303     BCF 0x3, 0x6
  0638    00C8     MOVWF 0x48
  0639    01C9     CLRF 0x49
  063A    01CA     CLRF 0x4a
  063B    01CB     CLRF 0x4b
172:               	fosc = 1000000 * clock;					// Calcola la
frequenza reale
  063C    3040     MOVLW 0x40
  063D    00F4     MOVWF 0x74
  063E    3042     MOVLW 0x42
  063F    00F5     MOVWF 0x75
  0640    300F     MOVLW 0xf
  0641    00F6     MOVWF 0x76
  0642    3000     MOVLW 0
  0643    00F7     MOVWF 0x77
  0644    084E     MOVF 0x4e, W
  0645    00F0     MOVWF 0x70
  0646    01F1     CLRF 0x71
  0647    01F2     CLRF 0x72
  0648    01F3     CLRF 0x73
  0649    120A     BCF 0xa, 0x4
  064A    118A     BCF 0xa, 0x3
  064B    27C3     CALL 0x7c3
  064C    120A     BCF 0xa, 0x4
  064D    118A     BCF 0xa, 0x3
  064E    0870     MOVF 0x70, W
  064F    00BC     MOVWF 0x3c
  0650    0871     MOVF 0x71, W
  0651    00BD     MOVWF 0x3d
  0652    0872     MOVF 0x72, W
  0653    00BE     MOVWF 0x3e
  0654    0873     MOVF 0x73, W
  0655    00BF     MOVWF 0x3f
173:               	div = k * baudrate;
  0656    0832     MOVF 0x32, W
  0657    00F4     MOVWF 0x74
  0658    0833     MOVF 0x33, W
  0659    00F5     MOVWF 0x75
  065A    0834     MOVF 0x34, W
  065B    00F6     MOVWF 0x76
  065C    0835     MOVF 0x35, W
  065D    00F7     MOVWF 0x77
  065E    084D     MOVF 0x4d, W
  065F    00F0     MOVWF 0x70
  0660    01F1     CLRF 0x71
  0661    01F2     CLRF 0x72
  0662    01F3     CLRF 0x73
  0663    120A     BCF 0xa, 0x4
  0664    118A     BCF 0xa, 0x3
  0665    27C3     CALL 0x7c3
  0666    120A     BCF 0xa, 0x4
  0667    118A     BCF 0xa, 0x3
  0668    0870     MOVF 0x70, W
  0669    00C0     MOVWF 0x40
  066A    0871     MOVF 0x71, W
  066B    00C1     MOVWF 0x41
  066C    0872     MOVF 0x72, W
  066D    00C2     MOVWF 0x42
  066E    0873     MOVF 0x73, W
  066F    00C3     MOVWF 0x43
174:               	quot = fosc / div;						// Divisione parte intera
  0670    0840     MOVF 0x40, W
  0671    00F4     MOVWF 0x74
  0672    0841     MOVF 0x41, W
  0673    00F5     MOVWF 0x75
  0674    0842     MOVF 0x42, W
  0675    00F6     MOVWF 0x76
  0676    0843     MOVF 0x43, W
  0677    00F7     MOVWF 0x77
  0678    083C     MOVF 0x3c, W
  0679    00F0     MOVWF 0x70
  067A    083D     MOVF 0x3d, W
  067B    00F1     MOVWF 0x71
  067C    083E     MOVF 0x3e, W
  067D    00F2     MOVWF 0x72
  067E    083F     MOVF 0x3f, W
  067F    00F3     MOVWF 0x73
  0680    120A     BCF 0xa, 0x4
  0681    118A     BCF 0xa, 0x3
  0682    2747     CALL 0x747
  0683    120A     BCF 0xa, 0x4
  0684    118A     BCF 0xa, 0x3
  0685    0870     MOVF 0x70, W
  0686    00C4     MOVWF 0x44
  0687    0871     MOVF 0x71, W
  0688    00C5     MOVWF 0x45
  0689    0872     MOVF 0x72, W
  068A    00C6     MOVWF 0x46
  068B    0873     MOVF 0x73, W
  068C    00C7     MOVWF 0x47
175:               	rem = fosc - (quot*div);				// Resto
  068D    0840     MOVF 0x40, W
  068E    00F4     MOVWF 0x74
  068F    0841     MOVF 0x41, W
  0690    00F5     MOVWF 0x75
  0691    0842     MOVF 0x42, W
  0692    00F6     MOVWF 0x76
  0693    0843     MOVF 0x43, W
  0694    00F7     MOVWF 0x77
  0695    0844     MOVF 0x44, W
  0696    00F0     MOVWF 0x70
  0697    0845     MOVF 0x45, W
  0698    00F1     MOVWF 0x71
  0699    0846     MOVF 0x46, W
  069A    00F2     MOVWF 0x72
  069B    0847     MOVF 0x47, W
  069C    00F3     MOVWF 0x73
  069D    120A     BCF 0xa, 0x4
  069E    118A     BCF 0xa, 0x3
  069F    27C3     CALL 0x7c3
  06A0    120A     BCF 0xa, 0x4
  06A1    118A     BCF 0xa, 0x3
  06A2    0870     MOVF 0x70, W
  06A3    023C     SUBWF 0x3c, W
  06A4    00F4     MOVWF 0x74
  06A5    083D     MOVF 0x3d, W
  06A6    00F5     MOVWF 0x75
  06A7    0871     MOVF 0x71, W
  06A8    1C03     BTFSS 0x3, 0
  06A9    0F71     INCFSZ 0x71, W
  06AA    02F5     SUBWF 0x75, F
  06AB    083E     MOVF 0x3e, W
  06AC    00F6     MOVWF 0x76
  06AD    0872     MOVF 0x72, W
  06AE    1C03     BTFSS 0x3, 0
  06AF    0F72     INCFSZ 0x72, W
  06B0    02F6     SUBWF 0x76, F
  06B1    083F     MOVF 0x3f, W
  06B2    00F7     MOVWF 0x77
  06B3    0873     MOVF 0x73, W
  06B4    1C03     BTFSS 0x3, 0
  06B5    0F73     INCFSZ 0x73, W
  06B6    02F7     SUBWF 0x77, F
  06B7    0874     MOVF 0x74, W
  06B8    00B8     MOVWF 0x38
  06B9    0875     MOVF 0x75, W
  06BA    00B9     MOVWF 0x39
  06BB    0876     MOVF 0x76, W
  06BC    00BA     MOVWF 0x3a
  06BD    0877     MOVF 0x77, W
  06BE    00BB     MOVWF 0x3b
176:               	if (rem > (div/two)) round = 1;			// Verifica
resto per ...
  06BF    0848     MOVF 0x48, W
  06C0    00F4     MOVWF 0x74
  06C1    0849     MOVF 0x49, W
  06C2    00F5     MOVWF 0x75
  06C3    084A     MOVF 0x4a, W
  06C4    00F6     MOVWF 0x76
  06C5    084B     MOVF 0x4b, W
  06C6    00F7     MOVWF 0x77
  06C7    0840     MOVF 0x40, W
  06C8    00F0     MOVWF 0x70
  06C9    0841     MOVF 0x41, W
  06CA    00F1     MOVWF 0x71
  06CB    0842     MOVF 0x42, W
  06CC    00F2     MOVWF 0x72
  06CD    0843     MOVF 0x43, W
  06CE    00F3     MOVWF 0x73
  06CF    120A     BCF 0xa, 0x4
  06D0    118A     BCF 0xa, 0x3
  06D1    2747     CALL 0x747
  06D2    120A     BCF 0xa, 0x4
  06D3    118A     BCF 0xa, 0x3
  06D4    083B     MOVF 0x3b, W
  06D5    0273     SUBWF 0x73, W
  06D6    1D03     BTFSS 0x3, 0x2
  06D7    2EE2     GOTO 0x6e2
  06D8    083A     MOVF 0x3a, W
  06D9    0272     SUBWF 0x72, W
  06DA    1D03     BTFSS 0x3, 0x2
  06DB    2EE2     GOTO 0x6e2
  06DC    0839     MOVF 0x39, W
  06DD    0271     SUBWF 0x71, W
  06DE    1D03     BTFSS 0x3, 0x2
  06DF    2EE2     GOTO 0x6e2
  06E0    0838     MOVF 0x38, W
  06E1    0270     SUBWF 0x70, W
  06E2    1803     BTFSC 0x3, 0
  06E3    2EE5     GOTO 0x6e5
  06E4    2EE6     GOTO 0x6e6
  06E5    2EE9     GOTO 0x6e9
  06E6    01B7     CLRF 0x37
  06E7    0AB7     INCF 0x37, F
  06E8    2EEC     GOTO 0x6ec
177:               	else round = 0;							// arrotondamento
  06E9    1283     BCF 0x3, 0x5
  06EA    1303     BCF 0x3, 0x6
  06EB    01B7     CLRF 0x37
178:               	brg = quot + round - 1;
  06EC    1283     BCF 0x3, 0x5
  06ED    1303     BCF 0x3, 0x6
  06EE    0837     MOVF 0x37, W
  06EF    0744     ADDWF 0x44, W
  06F0    00F0     MOVWF 0x70
  06F1    0370     DECF 0x70, W
  06F2    00CC     MOVWF 0x4c
179:               	return brg;
  06F3    084C     MOVF 0x4c, W
  06F4    2EF5     GOTO 0x6f5
180:               }
  06F5    1303     BCF 0x3, 0x6
---  C:\Documents and Settings\Administrator\Desktop\prova\rs232.c
------------------------------
1:                 //
---------------------------------------------------------------
2:                 // File:
TUart.c                                                -
3:                 // Autore:  Nicola Sellitto
snic...@yahoo.it
                  -
4:                 // Versione:
0.1                                                -
5:                 // Data:  16 Maggio
2003                                         -
6:                 // Descrizione: Esempio di comunicazione seriale
con il PC       -
7:                 // Verifiche: Prove eseguite con 16F876
20Mhz                    -
8:                 // Note: Vedere Uart.c per le routine di gestione
seriale        -
9:                 //
---------------------------------------------------------------
10:
11:
12:                #include <pic.h>
13:                #include "delay.c"
14:                #include "macro.h"
15:                #include "ascii.c"
16:                #include "uart.c"
17:
18:                main(void) {
19:                char c;
20:                unsigned char clock;
21:                unsigned long baudrate;
22:                char string[5];
23:                unsigned char rc;
24:
25:                ADCON0 = 0;
  052C    1283     BCF 0x3, 0x5
  052D    1303     BCF 0x3, 0x6
  052E    019F     CLRF 0x1f
26:                ADCON1 = 7;
  052F    3007     MOVLW 0x7
  0530    1683     BSF 0x3, 0x5
  0531    009F     MOVWF 0x1f
27:                PORTA = 0x00; // Azzera linee PortA
  0532    1283     BCF 0x3, 0x5
  0533    0185     CLRF 0x5
28:                PORTB = 0x00;   // Azzera linee PortB
  0534    0186     CLRF 0x6
29:                PORTC = 0x00;   // Azzera linea PortC
  0535    0187     CLRF 0x7
30:                TRISA = 0x00;  // Imposta linee PortA come output
  0536    1683     BSF 0x3, 0x5
  0537    0185     CLRF 0x5
31:                TRISB = 0x00;  // Imposta linee PortB come output
  0538    0186     CLRF 0x6
32:                TRISC = 0x80;   // Imposta linee PortC come output
  0539    3080     MOVLW 0x80
  053A    0087     MOVWF 0x7
33:                                     // tranne RC7/Rx come input
34:
35:                //DelayMs(250);
36:                //DelayMs(250);
37:                //DelayMs(250);
38:                //DelayMs(250);
39:
40:                // Inizializza la seriale
41:                clock = 20;                  //inserire qui il
valore del quarzo
  053B    3014     MOVLW 0x14
  053C    1283     BCF 0x3, 0x5
  053D    00A1     MOVWF 0x21
42:                baudrate = 2400;
  053E    3060     MOVLW 0x60
  053F    00A2     MOVWF 0x22
  0540    3009     MOVLW 0x9
  0541    00A3     MOVWF 0x23
  0542    3000     MOVLW 0
  0543    00A4     MOVWF 0x24
  0544    3000     MOVLW 0
  0545    00A5     MOVWF 0x25
43:                    rc = UartInit(clock, baudrate,
UART_CFG_BITSTOP_1);
  0546    0822     MOVF 0x22, W
  0547    00AC     MOVWF 0x2c
  0548    0823     MOVF 0x23, W
  0549    00AD     MOVWF 0x2d
  054A    0824     MOVF 0x24, W
  054B    00AE     MOVWF 0x2e
  054C    0825     MOVF 0x25, W
  054D    00AF     MOVWF 0x2f
  054E    3004     MOVLW 0x4
  054F    00B0     MOVWF 0x30
  0550    0821     MOVF 0x21, W
  0551    120A     BCF 0xa, 0x4
  0552    118A     BCF 0xa, 0x3
  0553    24D6     CALL 0x4d6
  0554    120A     BCF 0xa, 0x4
  0555    118A     BCF 0xa, 0x3
  0556    00AB     MOVWF 0x2b
44:                int2dec(rc, string);
  0557    082B     MOVF 0x2b, W
  0558    00AC     MOVWF 0x2c
  0559    01AD     CLRF 0x2d
  055A    3026     MOVLW 0x26
  055B    00AE     MOVWF 0x2e
  055C    120A     BCF 0xa, 0x4
  055D    118A     BCF 0xa, 0x3
  055E    259D     CALL 0x59d
  055F    120A     BCF 0xa, 0x4
  0560    118A     BCF 0xa, 0x3
45:
46:                //DelayMs(250);
47:                    UartPutch('-');
  0561    302D     MOVLW 0x2d
  0562    120A     BCF 0xa, 0x4
  0563    118A     BCF 0xa, 0x3
  0564    2404     CALL 0x404
  0565    120A     BCF 0xa, 0x4
  0566    118A     BCF 0xa, 0x3
48:                    UartPutch('-');
  0567    302D     MOVLW 0x2d
  0568    120A     BCF 0xa, 0x4
  0569    118A     BCF 0xa, 0x3
  056A    2404     CALL 0x404
  056B    120A     BCF 0xa, 0x4
  056C    118A     BCF 0xa, 0x3
49:                    UartPuts(string);
  056D    3026     MOVLW 0x26
  056E    00AC     MOVWF 0x2c
  056F    3080     MOVLW 0x80
  0570    00AD     MOVWF 0x2d
  0571    120A     BCF 0xa, 0x4
  0572    118A     BCF 0xa, 0x3
  0573    246A     CALL 0x46a
  0574    120A     BCF 0xa, 0x4
  0575    118A     BCF 0xa, 0x3
50:                    UartPutch('-');
  0576    302D     MOVLW 0x2d
  0577    120A     BCF 0xa, 0x4
  0578    118A     BCF 0xa, 0x3
  0579    2404     CALL 0x404
  057A    120A     BCF 0xa, 0x4
  057B    118A     BCF 0xa, 0x3
51:                    UartPutch('-');
  057C    302D     MOVLW 0x2d
  057D    120A     BCF 0xa, 0x4
  057E    118A     BCF 0xa, 0x3
  057F    2404     CALL 0x404
  0580    120A     BCF 0xa, 0x4
  0581    118A     BCF 0xa, 0x3
52:                    UartPuts("Test seriale v0.2");
  0582    3025     MOVLW 0x25
  0583    00AC     MOVWF 0x2c
  0584    3000     MOVLW 0
  0585    00AD     MOVWF 0x2d
  0586    120A     BCF 0xa, 0x4
  0587    118A     BCF 0xa, 0x3
  0588    246A     CALL 0x46a
  0589    120A     BCF 0xa, 0x4
  058A    118A     BCF 0xa, 0x3
53:
54:                while (TRUE) {
  058B    2D98     GOTO 0x598
  0598    2D8C     GOTO 0x58c
55:                  c = UartGetch();
  058C    120A     BCF 0xa, 0x4
  058D    118A     BCF 0xa, 0x3
  058E    23D7     CALL 0x3d7
  058F    120A     BCF 0xa, 0x4
  0590    118A     BCF 0xa, 0x3
  0591    00A0     MOVWF 0x20
56:                  UartPutch(c);
  0592    0820     MOVF 0x20, W
  0593    120A     BCF 0xa, 0x4
  0594    118A     BCF 0xa, 0x3
  0595    2404     CALL 0x404
  0596    120A     BCF 0xa, 0x4
  0597    118A     BCF 0xa, 0x3
57:                }
58:
59:                }
  0599    0183     CLRF 0x3

 ha scritto nel messaggio 
news:1170938909.2...@j27g2000cwj.googlegroups.com...


 l'hai messo un max232 ?
l'ho messo.....puo' essersi fottuta la uart del pic?

Ciao
Byte di configurazione ?
Il lampeggio di un led ti funziona sull' hardware che stai usando ?
Alx PD 


xt boden wrt attivi.......
be il lampeggio del led sarebbe stato il passo successivo ma già se
non riesco a connetterlo con l'rs232 del pc e' un po' difficile
concentrarsi sul resto....e pensare che con l'16f84 riesco
perfettamente a ricevere e inviare un carattere ...mah....
sentite io lo programma con il multipippo e peraltro non
alimentato....non mi dà errore 0h0000 etc..etc...quindi presumo che lo
riesca a programmare..puo' essere anche li' l'errore?


ok c'e l'ho fatta!!!!!!!.........non avevo collegato la gnd della
porta rs232 alla gnd generale......mortaccimia!!!!!
adesso il prossimo passo e' collegare il chip tramite rtf saw 433, con
l'16f84 ci sono riuscito alla grande.....pero' mi si pone un
problema...ovvero...
come faccio ad ordinare il RESET via PC e non manualmente cosi che' il
pic avvia il programma caricato con il bootloader?...mah...vedremo....