{"id":1808,"date":"2017-07-14T13:30:23","date_gmt":"2017-07-14T04:30:23","guid":{"rendered":"http:\/\/otsuka.biz\/blog1\/?p=1808"},"modified":"2024-02-12T17:02:18","modified_gmt":"2024-02-12T08:02:18","slug":"ntp-client","status":"publish","type":"post","link":"https:\/\/otsuka.biz\/blog1\/ntp-client\/","title":{"rendered":"NTP client as a simple clock using PIC18F27J53 and ENC28J60"},"content":{"rendered":"<p>&lt;&lt; Introduction in Japanese &gt;&gt;<\/p>\n<p>\u81ea\u4f5c\u00a0Ethernet board \uff08\u5e73\u621029\u5e744\u670823\u65e5\u306e\u7a3f\uff09\u3092\u7528\u3044\u3066 NTP server \u306b\u63a5\u7d9a\u3057\u3001\u73fe\u5728\u6642\u523b\u3092\u53d6\u5f97\u8868\u793a\u3059\u308b\u5b9f\u9a13\u3092\u884c\u3063\u305f\u3002\u63a5\u7d9a\u3059\u308b NTP server \u3068\u3057\u3066\u60c5\u5831\u901a\u4fe1\u7814\u7a76\u6a5f\u69cb\u306e ntp.nict.jp \u3092\u5229\u7528\u3057\u305f\u3002<\/p>\n<p>Microchip \u793e\u304c\u63d0\u4f9b\u3059\u308bTCP\/IP \u30b9\u30bf\u30c3\u30af\u306b\u542b\u307e\u308c\u308b\u00a0Berkeley Socket API \u3092\u7528\u3044\u3066\u00a0UDP client \u3092\u4f5c\u6210\u3057\u305f\u3002<\/p>\n<p>\u5b9f\u7528\u3068\u3057\u3066 NTP server \u304b\u3089\u306e\u53d7\u4fe1\u30c7\u30fc\u30bf\u3092\u57fa\u6e96\u306b\u3001CCP \u3068 Timer1 \u306b\u3088\u308a1\u79d2\u5272\u8fbc\u3092\u767a\u751f\u3055\u305b\u3066\u6642\u523b\u66f4\u65b0\u3057\u3001\u5353\u4e0a\u6642\u8a08\u3068\u3057\u3066\u306e\u8a55\u4fa1\u3092\u884c\u3063\u305f\u3002<\/p>\n<p><a href=\"http:\/\/otsuka.biz\/blog1\/wp-content\/uploads\/2017\/04\/NTP-client.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1811\" src=\"http:\/\/otsuka.biz\/blog1\/wp-content\/uploads\/2017\/04\/NTP-client.jpg\" alt=\"\" width=\"3721\" height=\"1881\" srcset=\"https:\/\/otsuka.biz\/blog1\/wp-content\/uploads\/2017\/04\/NTP-client.jpg 3721w, https:\/\/otsuka.biz\/blog1\/wp-content\/uploads\/2017\/04\/NTP-client-300x152.jpg 300w, https:\/\/otsuka.biz\/blog1\/wp-content\/uploads\/2017\/04\/NTP-client-768x388.jpg 768w, https:\/\/otsuka.biz\/blog1\/wp-content\/uploads\/2017\/04\/NTP-client-1024x518.jpg 1024w\" sizes=\"auto, (max-width: 3721px) 100vw, 3721px\" \/><\/a><\/p>\n<p>The &#8220;BerkeleyUDPClientDemo.c&#8221; in the\u00a0TCP\/IP stack of Microchip Libraries for Applications v2013-06-15 is\u00a0at work on\u00a0my board.<\/p>\n<p>The Ethernet board was previously reported in my page on Apr. 23, 2017.<\/p>\n<p><a href=\"https:\/\/www.nict.go.jp\/en\/\">The NTP server of National Institute of Information and Communications Technology<\/a> is used in this project and Coordinated Universal Time (UTC) is converted to Japan Standard Time (JST: UTC + 9 hours).<\/p>\n<p><span class=\"KejjeYrKwrd\">Furthermore<\/span>, this test board works as a simple clock.\u00a0 An interruption of every one second is generated by the CCP1 module, which increments the timestamp obtained from the NTP server.<\/p>\n<p>&lt;&lt; Sample code\u00a0of\u00a0the NTP client\u00a0&gt;&gt;<\/p>\n<div class='w3eden'><!-- WPDM Link Template: Default Template -->\n\n<div class=\"link-template-default card mb-2\">\n    <div class=\"card-body\">\n        <div class=\"media\">\n            <div class=\"mr-3 img-48\"><img decoding=\"async\" class=\"wpdm_icon\" alt=\"\u30a2\u30a4\u30b3\u30f3\" src=\"data:image\/svg+xml;base64,CiAgICAgICAgICAgIDxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB2aWV3Qm94PSIwIDAgNDAgNDAiPgogICAgICAgICAgICAgICAgPGRlZnM+CiAgICAgICAgICAgICAgICAgICAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkaWVudCIgeDE9IjAiIHkxPSIwIiB4Mj0iMCIgeTI9IjEiPgogICAgICAgICAgICAgICAgICAgICAgICA8c3RvcCBzdG9wLWNvbG9yPSIjMjY5ZGVmIiBvZmZzZXQ9IjAiLz4KICAgICAgICAgICAgICAgICAgICAgICAgPHN0b3Agc3RvcC1jb2xvcj0iIzI2YmRlZiIgb2Zmc2V0PSIxIi8+CiAgICAgICAgICAgICAgICAgICAgPC9saW5lYXJHcmFkaWVudD4KICAgICAgICAgICAgICAgIDwvZGVmcz4KICAgICAgICAgICAgICAgIDxnPgogICAgICAgICAgICAgICAgICAgIDxyZWN0IGZpbGw9InVybCgjZ3JhZGllbnQpIiB4PSIwIiB5PSIwIiB3aWR0aD0iNDAiIGhlaWdodD0iNDAiIHJ4PSIzIiByeT0iMyIvPgogICAgICAgICAgICAgICAgICAgIDx0ZXh0IHg9IjUiIHk9IjE5IiBmb250LWZhbWlseT0iQXJpYWwsIEhlbHZldGljYSwgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIxM3B4IiBsZXR0ZXItc3BhY2luZz0iMSIgZmlsbD0iI0ZGRkZGRiI+CiAgICAgICAgICAgICAgICAgICAgICAgIDx0c3Bhbj5MWkg8L3RzcGFuPgogICAgICAgICAgICAgICAgICAgICAgICA8dHNwYW4geD0iNiIgeT0iMjgiPl88L3RzcGFuPgogICAgICAgICAgICAgICAgICAgIDwvdGV4dD4KICAgICAgICAgICAgICAgIDwvZz4KICAgICAgICAgICAgPC9zdmc+CgoJCQk=\" \/><\/div>\n            <div class=\"media-body\">\n                <h3 class=\"package-title\"><a href='https:\/\/otsuka.biz\/blog1\/download\/ntp_enc28j60\/'>NTP_ENC28J60<\/a><\/h3>\n                <div class=\"text-muted text-small\"><i class=\"fas fa-copy\"><\/i> 1 \u30d5\u30a1\u30a4\u30eb <i class=\"fas fa-hdd ml-3\"><\/i> 947.08 KB<\/div>\n            <\/div>\n            <div class=\"ml-3\">\n                <a class='wpdm-download-link download-on-click btn btn-primary ' rel='nofollow' href='#' data-downloadurl=\"https:\/\/otsuka.biz\/blog1\/download\/ntp_enc28j60\/?wpdmdl=3387&refresh=69e79f86de89c1776787334\">\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9<\/a>\n            <\/div>\n        <\/div>\n    <\/div>\n<\/div>\n\n<\/div>\n<p>(Compiled by\u00a0the C18 under\u00a0the large code model\u00a0on the\u00a0MPLAB X IDE)<\/p>\n<p>In TCPIPConfig.h, the default network configuration must be adjusted to your local network (MAC address, IP\u00a0address and so on).<\/p>\n<p>In addition, STACK_USE_ICMP_SERVER, STACK_USE_DNS and STACK_USE_BERKELEY_API\u00a0are defined so that the Ethernet board\u00a0can work as a NTP client using the Berkeley Socket.<\/p>\n<p>&lt;&lt; Operation of the NTP client &gt;&gt;<\/p>\n<p>Initialization:\u00a0\u00a0\u00a0 If the Ethernet board is connected to the Internet for the first time, the current time can be automatically obtained from the NTP server.<\/p>\n<p>Adjustment of the time:\u00a0\u00a0\u00a0 Every time the RB3 pin (BUTTON 0) is pulled down, the current time will be gotten from the NTP server.<\/p>\n<p>\u4f7f\u7528\u65b9\u6cd5\uff1a\u3000TCPIPConfig.h \u30d5\u30a1\u30a4\u30eb\u306b\u30ed\u30fc\u30ab\u30eb\u30fb\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u306e\u60c5\u5831\u3092\u8a2d\u5b9a\u3002\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u306b\u63a5\u7d9a\u3059\u308b\u3068\u3001\u521d\u56de\u306e\u6642\u523b\u8a2d\u5b9a\u306f\u81ea\u52d5\u7684\u306b NTP \u30b5\u30fc\u30d0\u30fc\u306b\u63a5\u7d9a\u3055\u308c\u3066\u6642\u9593\u3092\u523b\u307f\u59cb\u3081\u308b\u3002\uff12\u56de\u76ee\u4ee5\u964d\u306e\u6642\u523b\u88dc\u6b63\u306b\u306f\u3001\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u63a5\u7d9a\u3055\u308c\u305f\u72b6\u614b\u3067\u30b9\u30a4\u30c3\u30c1 (RB3) \u3092\u62bc\u3059\u3068 NTP \u30b5\u30fc\u30d0\u30fc\u306b\u63a5\u7d9a\u3055\u308c\u3066\u73fe\u5728\u6642\u523b\u306b\u66f4\u65b0\u3055\u308c\u308b\u3002<\/p>\n<p>&lt;&lt; Summary in Japanese &gt;&gt;<\/p>\n<p>\u5b9f\u9a13\u30dc\u30fc\u30c9\u306b\u306f\u30b9\u30a4\u30c3\u30c1\u304c\u5c11\u306a\u304f\u624b\u52d5\u3067\u306e\u6642\u523b\u8a2d\u5b9a\u306f\u51fa\u6765\u306a\u3044\u304c\u3001\u81ea\u5b85\u306e LAN \u74b0\u5883\u306b\u63a5\u7d9a\u3057\u3066 NTP server \u304b\u3089\u6642\u523b\u53d6\u5f97\u3092\u884c\u3046\u4e8b\u306f\u3067\u304d\u305f\u3002<\/p>\n<p>\u6642\u8a08\u3068\u3057\u3066\u306e\u7cbe\u5ea6\u306f\u3001NTP server \u304b\u3089\u306e\u30ec\u30b9\u30dd\u30f3\u30b9\u30fb\u30c7\u30fc\u30bf\u3092\u5358\u7d14\u306b\u5229\u7528\u3057\u3066\u3044\u308b\u3060\u3051\u3067\u3001\u901a\u4fe1\u6642\u306e\u30bf\u30a4\u30e0\u30e9\u30b0\u306a\u3069\u306f\u8003\u616e\u3057\u3066\u3044\u306a\u3044\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001\u901a\u4fe1\u6642\u306e\u30bf\u30a4\u30e0\u30e9\u30b0\u3092\u8a31\u5bb9\u3057\u3001\u304b\u3064\u6c34\u6676\u767a\u632f\u5b50\u3092\u7528\u3044\u305f\u306a\u3089\u3070\u983b\u56de\u306e\u6642\u523b\u6821\u6b63\u306f\u4e0d\u8981\u3067\u3042\u308b\u3002\u66f4\u306b\u7bc0\u96fb\u306e\u5de5\u592b\u3092\u52a0\u3048\u305f\u306a\u3089\u3070\u3001\u4e7e\u96fb\u6c60\u5f0f\u306e\u5353\u4e0a\u6642\u8a08\u3068\u3057\u3066\u306f\u5341\u5206\u306a\u6709\u7528\u6027\u3092\u6301\u3064\u3068\u8003\u3048\u308b\u3002<\/p>\n<p>\u5353\u4e0a\u6642\u8a08\u306e\u96fb\u6c60\u4ea4\u63db\u6642\u306b\u3001\u5c0f\u3055\u306a\u30b9\u30a4\u30c3\u30c1\u3067\u6642\u523b\u3092\u624b\u5408\u308f\u305b\u3059\u308b\u624b\u9593\u3068 \u3001\u30b1\u30fc\u30d6\u30eb\u3067 LAN \u306b\u7e4b\u3044\u3067\u6642\u523b\u8a2d\u5b9a\u3059\u308b\u624b\u9593\u3001\u3069\u3063\u3061\u3089\u3082\u7169\u308f\u3057\u3044\u3068\u8a00\u308f\u308c\u308b\u306e\u306f\u899a\u609f\u3057\u3066\u3044\u308b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&lt;&lt; Introduction in Japanese &gt;&gt; \u81ea\u4f5c\u00a0Ethernet board \uff08\u5e73\u621029\u5e744\u670823\u65e5\u306e\u7a3f\uff09\u3092\u7528\u3044\u3066 NTP server \u306b\u63a5\u7d9a\u3057\u3001\u73fe\u5728\u6642\u523b\u3092\u53d6\u5f97\u8868\u793a\u3059\u308b\u5b9f\u9a13\u3092 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"vkexunit_cta_each_option":"","footnotes":""},"categories":[2,12],"tags":[],"class_list":["post-1808","post","type-post","status-publish","format-standard","hentry","category-pic","category-internet"],"_links":{"self":[{"href":"https:\/\/otsuka.biz\/blog1\/wp-json\/wp\/v2\/posts\/1808","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/otsuka.biz\/blog1\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/otsuka.biz\/blog1\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/otsuka.biz\/blog1\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/otsuka.biz\/blog1\/wp-json\/wp\/v2\/comments?post=1808"}],"version-history":[{"count":2,"href":"https:\/\/otsuka.biz\/blog1\/wp-json\/wp\/v2\/posts\/1808\/revisions"}],"predecessor-version":[{"id":3388,"href":"https:\/\/otsuka.biz\/blog1\/wp-json\/wp\/v2\/posts\/1808\/revisions\/3388"}],"wp:attachment":[{"href":"https:\/\/otsuka.biz\/blog1\/wp-json\/wp\/v2\/media?parent=1808"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/otsuka.biz\/blog1\/wp-json\/wp\/v2\/categories?post=1808"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/otsuka.biz\/blog1\/wp-json\/wp\/v2\/tags?post=1808"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}