Вы находитесь на странице: 1из 76

( )

!
n
n
n


n
n
n
n
n
n
n
n


n
n
n
n
n
n

n
n

n
n
n


#if defined(__PICC__) || defined(__PICC18__)
typedef
typedef
typedef
typedef
typedef
typedef

signed
signed
signed
unsigned
unsigned
unsigned

char
int
long
char
int
long

S08;
S16;
S32;
U08;
U16;
U32;

#endif
:
: char, int, long.


n
n
n
n


:
n
n
n
n ( )
:
n
n
n

n
n
n
n
n

:
:
char Counter;
Counter = 10;
while (Counter-- >= 0) ...;

:
signed char Coutner;
Counter = 10;
while (Counter-- >= 0) ...;

:
int
i;
void *p;

:
p = &i;

:
p = (void*)&i;



unsigned char lo, hi;
unsigned int ui;

:
lo = *((unsigned char*)&ui + 0);
hi = *((unsigned char*)&ui + 1);

:
lo = ui & 0xFF;
hi = ui >> 8;

myfunc
myfunc
int myfunc
int myfunc

()
(void)
()
(void)

//
//
//
//

:
:
while (!TRMT);
TXREG = Data;

//

:
while (!TRMT) continue; //
TXREG = Data;

: switch
switch :
n
n
n

default
case
break
break

switch (...)
{
case 0x00:
...
break;
case 0x01:
...
// break; //
//
//
//
//
//
case 0x02:
...
break;
default:
...

//
//
//
//
//


break, ,

0x01
0x02,
break

,
,
switch

n
n !
typedef struct
{
unsigned int
unsigned int
unsigned int
} T_CLOCK;

seconds : 6;
minutes : 6;
hours
: 4;



:
t=sqrt(p*r/(a+b*b+v))+sin(sqrt(b*b-4*a*c)/(1<<(SHIFT_CONST-1)));

:
A
B
C
D

=
=
=
=

p*r;
a + b*b + v;
b*b 4*a*c;
1 << (SHIFT_CONST-1);

if (B == 0) ...;
if (C < 0) ...;
E = A/B;
if (E < 0) ...;

// : 0
// : .
// : .

t = sqrt(E) + sin(sqrt(C)/D);


n
n
n







n
n



:
char String[25];
...
for (i = 0; i <= 24; i++) String[i] = ;

:
#define STRING_SIZE
25
...
char String[STRING_SIZE];
...
for (i = 0; i <= STRING_SIZE - 1; i++) String[i] = ;


:
#define FOSC
4000000
#define MAX_INTERATIONS
10000
#define MIDDLE_TEMPERATURE
25

:
#define FOSC
4000000L
#define MAX_INTERATIONS
10000L
#define MIDDLE_TEMPERATURE
25.0



:
#define BAUDRATE
...
SPBRG = BAUDRATE;

25

// 9600 for 4 MHz

:
#define FOSC
4000000L
#define BAUDRATE
9600L
...
SPBRG = ((FOSC + BAUDRATE*8) / (BAUDRATE*16) 1;


//
#define FOSC
#define BAUDRATE

4000000L
9600L

// ( )
#define SPBRG_CONST
((FOSC + BAUDRATE*8) / (BAUDRATE*16) - 1)
#define REAL_BAUDRATE ((FOSC + (SPBRG_CONST+1)*8)/((SPBRG_CONST + 1)*16))
#define BAUDRATE_ERROR (100L * ((BAUDRATE - REAL_BAUDRATE)) / (BAUDRATE))
// -2%..+2%
#if BAUDRATE_ERROR < -2 || BAUDRATE_ERROR > 2
#error " BAUDRATE"
#endif


:
TRISA = 21;
TRISB = 65;

// RA0,RA2,RA4 , RA1, RA3 -


// 65 = 0x41 = 0b01000001

TMR1H = 0xF0;
TMR1L = 0xD8;

// 10000

:
#define
#define
#define
...
TRISA =
TRISB =

TRISA_CONST
0b00010101
// RA0,RA2,RA4
TRISB_CONST
0b01000001
// RB0, RB6 -
TMR1_WRITE(t) { TMR1H = t >> 8; TMR1L = t & 0xFF;}
TRISA_CONST;
TRISB_CONST;

TMR1_WRITE(-10000);

// 10000



:
#define PIN_MASK_1
1 << 2
#define PIN_MASK_2
1 << 5
...
PORTB = PIN_MASK_1 + PIN_MASK_2;

PORTB = 1 << 2 + 1 << 5;

PORTB = 1 << (2 + 1) << 5 = 1 << 8



:
#define PIN_MASK_1
(1 << 2)
#define PIN_MASK_2
(1 << 5)
...
PORTB = PIN_MASK_1 + PIN_MASK_2;

PORTB = (1 << 2) + (1 << 5);


.



:
#define MUL_BY_3(a)
...
i = MUL_BY_3(4 + 1);

a * 3

i = 4 + 1 * 3;

// = 7

:
#define MUL_BY_3(a) (a) * 3
...
i = MUL_BY_3(4 + 1);

i = (4 + 1) * 3;

// = 15



:
#define I2C_CLOCK()

NOP(); SCL = 1; NOP(); SCL = 0;

...
if (...) I2C_CLOCK();

if (...) NOP(); SCL = 1; NOP(); SCL = 0;

:
#define I2C_CLOCK()

{ NOP(); SCL = 1; NOP(); SCL = 0; }


n
n
n
n

n
n

n
n



, :
n
n
n
n
n

n
n .
( SlickEdit)


( )


n


<>_<>_<>[_<>]
n

( ) ,
;

,
,

, -
(rom, timeout).


:
CopyOneByteFromROMToRAM
Check
compare_and_get_max
WriteByte

:
i2c_write_byte
eeprom_write_byte
lcd_write_byte

n _
n (
)
#define I2C_DEV_ADDR
#define I2C_ADDR_WIDTH

0xA0
16


n
n
n : T_ TYPE_
typedef struct
{
unsigned long
unsigned long
unsigned long
} T_CLOCK;

seconds
minutes
hours

:
:
:

6;
6;
5;


n
unsigned char
signed
long

BytesCounter;
XSize, YSize;



Counter:
for (Counter

= 0; Counter

< 40000; Counter++) ...;

,
wCounter:
for (wCounter = 0; wCounter < 40000; wCounter++)...;


s_ -
m_ -
g_ -


uc unsigned char
sc signed char
ui unsigned int (n)
si signed int (w)
..

s_ucBytesCounter = 160;


:
n
n
n
:
n
n

n
static signed char s_ucBytesCounter;

n
n


AN2000.PDF micrium



,

n
n (for, if, )

n
n
n
n
n


n
n
n
n
n
n
n
n
n



n
n


static unsigned char
BytesCounter;
static signed
int
Timer;
double Price;
char
*p, c;
...
{
BytesCounter = 0;
Timer
= 10;
Price
= 1.12;
p
= &c;
}

int sendto(
SOCKET
s,
const char
*buf,
int
len,
int
flags,
const struct sockaddr *to,
int
tolen
);

,
,

:

for(i=0;i<10;i++)a[i]=0;
if(j<k){a[0]=1;a[1]=2;}else{a[0]=3;a[1]=4;}

for (i = 0; i < 10; i++) a[i] = 0;


if (j < k)
{
a[0] =
a[1] =
}
else
{
a[0] =
a[1] =
}

1;
2;

3;
4;

n
n


n
n
n
n
n
n
n

,
,


, ,




n
n
n
n
n


, , ,

, ,


/*************************************************************
*
* Function:
rs_buf_delete
*
*-----------------------------------------------------------*
* description:
N
*
* parameters:
uchar N
*
* on return:
void
*
*************************************************************/
void rs_buf_delete (uchar N)
{
...


/****************************************************
*
* ...
* 1.6 (22.10.2009):
*
1. ...
*
2. ...
*
...
*
8. .., 17.09.2009:
*
rs_buf_delete
*
0
* ...
***************************************************/
...
void rs_buf_delete (signed char N)
{
// *1.6-8* if (N < 0) return;
if (N <= 0) return;
// *1.6-8*
...

void rs_buf_delete (signed char N)


{
if (N <= 0) return;
/*DEBUG*/
/*DEBUG*/
/*DEBUG*/
/*DEBUG*/
...

DebugCounter++;
pin_DEBUG = 1;
delay_ms(5);
pin_DEBUG = 0;



1.
RB0 = 1;

//

2.
if (BufSize > 0) // ,
//

3.
BufSize = 0;

// ,
//



4.
if (N < 15)

//

5. :
A = X / Y + Z;

// (*1*), ...,

6.
:
if (timer < 100 && V < 10) // 100
// 10


:
/* */
pin_DATA = 0;
pin_CLC = 0;
/* */
for (i = 0; i < BUF_SIZE; i++) Buf[i] = 0;
/* */
While (ReadData())
{
...


:
pin_DATA = 0;
pin_CLC = 0;

/* */

for (i = 0; i < BUF_SIZE; i++)


Buf[i] = 0;

/*

*/

while (ReadData())
{
...

/*

*/


:
/* EEPROM,
.
, . */
for (i = 0; i < BUF_SIZE; i++) ...;

:
/* EEPROM,
/* .
/* , .
for (i = 0; i < BUF_SIZE; i++) ...;

*/
*/
*/


:
/*
* EEPROM,
* .
* , .
*/
for (i = 0; i < BUF_SIZE; i++) ...;

// EEPROM,
// .
// , .
for (i = 0; i < BUF_SIZE; i++) ...;


case switch:
switch (result)
{
case 0:
...
break;
case 1:
...
break;
case 2:
...
break;
...
}

//
//
//
//
//
//
//
//
//
//
//
//

,
:
switch (ModemState)
{
case MODEM_OFF:

break;
case MODEM_READY:

break;
case MODEM_CALLING:

break;

//
//
//
//
//
//
//
//
//
//
//
//
//
//


:
n ,
,
.
.


n
n


n
n
n
n
n


n
n
n

n
n
n .


:
n

USART, I/O, .


EEPROM, , , LCD

ROM RAM
n


, :
n
n
n ,
,
:
n

signed
int a;
unsigned int b;
if (a > b) ...; // Warning:
// signed and unsigned comparison

:
if ((signed long)a > (signed long)b) ...;

if (a == b) ;
if (a = b) ; // Warning:
// Assignment inside relational expression

:
a = b;
if (a) ;


#define DEBUG_ENABLE
...
/*D*/ #ifdef DEBUG_ENABLE
/*D*/ pin_DEBUG = 1;
/*D*/ #endif

-
/*D*/ if (pin_DEBUG_ENABLE) pin_DEBUG = 1;

char * GetGPSData (void)


{
#ifdef DUMMY_GPS_IN
char test_string[] = $GPRMC,A,123456,;
return test_string;
#else
/*
* GPS */
#endif
}



HEX-
n


.
, . , 1979
n . , .
n . ,

n . , ,
2005
n http://micrium.com/download/an2000.pdf
n http://andromega.narod.ru/doc/micrium_an_2000_rus.pdf
________________________________________________
n

( www.pic24.ru)